我尝试使用php脚本将文件上传到服务器。我将MAMP
与PHP7.0.8
我有HTML表单:
<form enctype="multipart/form-data" action="hi" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
Send File: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
简单的php:
<?php
$uploaddir = 'img/';
print_r($uploadfile = $uploaddir.basename($_FILES['userfile']['name']));
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'info:';
print_r($_FILES);
echo "<br />";
print_r($_FILES['userfile']['error']);
print "</pre>";
?>
我的结果是:
可能的文件上传攻击!
info:Array
(
[userfile] => Array
(
[name] => high-school-icon.png
[type] => image/png
[tmp_name] => /Applications/MAMP/tmp/php/phpoaPmYv
[error] => 0
[size] => 1807
)
)
答案 0 :(得分:1)
错误:强>
action="hi"
将其更改为: action="simple.php"
<form enctype="multipart/form-data" action="simple.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
Send File: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
答案 1 :(得分:-2)
$uploaddir = 'img/';
的错误方式