PHP文件上传
<html>
<head>
<meta charset="utf-8">
<title>文件上传</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">文件名:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
需要手动新建目录uploads
<?php
if(isset($_POST['submit'])){
if(is_uploaded_file($_FILES['file']['tmp_name'])){
$arr=pathinfo($_FILES['file']['name']);
$newName=date('YmdGis').rand(1000,9999);
var_dump(move_uploaded_file($_FILES['file']['tmp_name'],"uploads/{$newName}.{$arr['extension']}"));
}
var_dump($_FILES);
}
?>
|