[英]PHP MIME Type, limit uploading file
I have this code 我有这个代码
if(isset($_FILES['uploadfile']))
{
$maxsize = 10485760; //10MBx1024
$acceptable = array(
'image/jpeg',
'image/jpg',
'image/gif',
'image/png',
'application/pdf',
'text/plain',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-word',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/zip',
'application/x-zip-compressed',
'application/x-compressed',
);
and this is the following parts: 这是以下部分:
if((!in_array($_FILES['uploadfile']['type'], $acceptable)) && (!empty($_FILES["uploadfile"]["type"])))
{
$msg= "<b><img src=redwarn.png'><font color='red'> This file is not accepted.</b></font>";
goto cancel;
}
The above code could limit the extension that user upload, but I tried to upload a IMAGE file, it come out an error that the file wasn't accepted, but I did add 'image/jpeg'
in the array, is there any error in my code? 上面的代码可能会限制用户上传的扩展名,但是我尝试上传IMAGE文件,结果是文件不被接受的错误,但是我确实在数组中添加了
'image/jpeg'
,是否有任何错误在我的代码中?
Thanks 谢谢
Replace your if
condition which is following 替换以下的
if
条件
if ($_FILES["uploadfile"]["error"] > 0){
//add your code here
//$maxsize=..
//$acceptable_array=...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.