所以现在我有了
<?php if (($_FILES["fileToUpload"]["type"] == "image/gif" || $_FILES["fileToUpload"]["type"] == "image/jpeg" || $_FILES["fileToUpload"]["type"] == "image/png") && $_FILES["fileToUpload"]["size"] < 10000000)
{
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
"upload/" . $_FILES["fileToUpload"]["name"]);
}
else
{
echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb";
}
?>
我仍然在接受其他声明。我想我应该把一切都做对。
这里是来自页面的一些html ..
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
但这不应该是问题
答案 0 :(得分:3)
您访问“fileToUpload”,但您的html输入字段被称为“已上传”,因此$ _FILES [“fileToUpload”]为空...
答案 1 :(得分:0)
检查$ _FILES的['type']
部分中提供的mime类型是不安全的。它是由上传文件的客户提供的数据,很容易被破坏。最好对服务器端检查文件类型并处理自己的数据,而不是信任客户端,说实话:
if ($_FILES['uploaded'] === UPLOAD_ERR_OK) {
// file was successfully uploaded
$info = getimagesize($_FILES['uploaded']['tmp_name']);
if (($info['mime'] != 'image/gif') && ($info['mime'] != 'image/jpeg')) {
// not a jpeg
} else {
// upload went ok, do more processing
}
} else {
die("File upload error, code #{$_FILES['uploaded']['error']}");
}