我正在处理一个 php 图片上传脚本,但遇到了一个奇怪的问题。文件已成功上传,但只有 10 字节左右。预览给了我错误:
无法打开文件“文件名”。它可能已损坏或使用了 Preview 无法识别的文件格式。
图片上传脚本:
$FileType = $_FILES['picture_file']['type'];
$FileSize = $_FILES['picture_file']['size'];
$FileName = $_FILES['picture_file']['name'];
$Dir = "uploads/";
if($_FILES){
if (($FileType == "image/gif")
|| ($FileType == "image/jpg")
|| ($FileType == "image/jpeg")
|| ($FileType == "image/png")
&& ($FileSize < 2097152)) {
if(move_uploaded_file($_FILES['picture_file']['tmp_name'], $Dir . $FileName === FALSE)){
echo "<div class='alert alert-danger'> Could not move uploaded file to \"uploads" . htmlentities($FileName) . "\"</div>\n";
} else {
mkdir($Dir, 0777);
file_put_contents($Dir . $FileName, $FileName);
echo "<div class='alert alert-success'>Successfully uploaded \"uploads/" .htmlentities($FileName) . "\"</div>\n";
}
} else {
echo "<div class='alert alert-danger'>File must be a JPG, JPEG, GIF or PNG and weigh <2MB. <strong><a class='alert-link' href='/nnash_ex2/'>Start over?</a></strong></div>";
}
}
我真的不知道为什么要上传部分文件,因此将不胜感激。