<html>
<head><title></title></head>
<body>
<form action="doAction.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="176942">
請選擇您要上傳的文件:
<input type="file" name="myFile"/><br/>
<input type="submit" value="上傳文件">
</form>
</body>
</html>
doAction.php
<?php
header('content-type:text/html;charset=utf-8');
//1.通過$_FILES文件上傳變量接收上傳文件信息
$fileInfo = $_FILES['myFile'];
$filename = $fileInfo['name'];
$type = $fileInfo['type'];
$tmp_name = $fileInfo['tmp_name'];
$size = $fileInfo['size'];
$error = $fileInfo['error'];
//2.判斷下錯誤號杆查,只有為0或者是UPLOAD_ERR_OK扰法,沒有錯誤發(fā)生烹笔,上傳成功
if ($error == UPLOAD_ERR_OK) {
if (move_uploaded_file($tmp_name, "uploads/" . $filename)) {
echo '文件' . $filename . '上傳成功';
} else {
echo "文件" . $filename . "上傳失敗";
}
} else {
//匹配錯誤信息
switch ($error) {
case 1:
echo "上傳文件超過了PHP配置文件中upload_max_file";
break;
case 2:
echo "超過了表單MAX_FILE_SIZE";
break;
case 3:
echo "文件部分被上傳";
break;
case 4:
echo "沒有選擇上傳文件";
break;
case 6:
echo "沒有找到臨時目錄";
break;
case 7:
case 8:
echo "系統(tǒng)錯誤";
break;
}
}
?>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者