我有这部分PHP用于pdf文件上传。当我上传一个 png文件时,我的echo语句返回image/png
,当我上传一个pdf时,我的application/pdf
回复,但这两个文件都不会上传,我仍然会收到&#34 ; 不是允许的文件类型"从交换机的默认情况发出警报。有什么想法吗?
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$uploadOk = 1;
// Check if upload is correct file type
if(isset($_POST["submit"])) {
$mime = finfo_file($finfo, $_FILES["fileToUpload"]["tmp_name"]);
echo "$mime";
switch ($mime) {
case 'image/png': //Type allowments
case 'application/pdf':
case 'pdf':
$uploadOk = 1;
default:
echo "<script type='text/javascript'>alert('Not the allowed file type');</script>"; //Messy JS alert message
$uploadOk = 0;
}
}