-1
不知道這裏有什麼問題。這是我的上傳文件,它適用於jpeg和png文件,但由於某種原因,我不知道,只要我選擇一個PDF文件,它會給我提供無效的文件類型錯誤。我已經嘗試了許多不同尺寸的pdf,並且我總是得到相同的錯誤。肯定有一些我只是沒有看到。文件上傳不能使用pdf
if (isset($_POST['uspid'])) {
$spid =mysqli_real_escape_string($mysqli, $_POST['uspid']);
}
$udir= "uploads/".$spid."/";
if(!is_dir($udir)){
mkdir("uploads/".$spid, 0777);
}
$ufile = $udir . basename($_FILES['fileToUpload']['name']);
$allexts = array("jpg", "jpeg", "gif", "png", "pdf");
$ext = end(explode(".", $_FILES["fileToUpload"]["name"]));
if ((($_FILES["fileToUpload"]["type"] == "image/gif")
|| ($_FILES["fileToUpload"]["type"] == "image/jpeg")
|| ($_FILES["fileToUpload"]["type"] == "image/pdf")
|| ($_FILES["fileToUpload"]["type"] == "image/pjpeg")
|| ($_FILES["fileToUpload"]["type"] == "image/png"))
&& ($_FILES["fileToUpload"]["size"] < 5000000)
&& in_array($ext, $allexts)){
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $ufile)) {
echo "File upload was successful.";
} else {
echo "An error has occured. Please try again.";
}
} else {
echo "Invalid file type. Please try again.";
}
代碼的頂部只是把文件放到合適的目錄和一切工作正常,唯一的問題是與PDF文件。
pdf的MIME類型爲application/pdf – vascowhite