<html>
<head>
<meta charset="UTF-8">
<title>上传文件</title>
</head>
<body>
<form action="up.php" method ="post" enctype="multipart/form-data" >
选择您要上传的文件:
<input type="hidden" name="MAX_FILE_SIZE" value="10">
<input type="file" name="myFile" accept="image/png" /><br>
<input type="submit" value="上传文件" />
</form>
</body>
</html>
<?php
//print_r($_FILES);
$filename = $_FILES['myFile']['name'];
$type = $_FILES['myFile']['type'];
$tmp_name = $_FILES['myFile']['tmp_name'];
$size = $_FILES['myFile']['size'];
$error = $_FILES['myFile']['error'];
if($error == 0){
if(move_uploaded_file($tmp_name, "upload/".$filename)){
echo '文件'.$filename.'上传成功';
}else{
echo "文件上传失败";
}
}else{
switch($error){
case 1:
echo "文件上传超过了PHP配置文件中upload_max_filesize选项的值";
break;
case 2:
echo "文件大小超过表单中上传文件大小的限制";
break;
case 3:
echo "文件部分被上传";
break;
case 4:
echo "没有文件被上传";
break;
case 6:
echo "找不到临时文件";
break;
case 7:
echo "文件写入失败";
break;
case 8:
echo "上传被php扩展程序中断";
break;
}
}