将文件上传到网络服务器时遇到问题。我创建了一个验证,以限制上传到我的服务器,受到stackoverflow上另一个帖子的启发。这个想法是用户应该只能将某些文件类型上传到服务器,以避免他上传脚本等。
$upfile = $_FILES['cont2'];
if($upfile) {
$acceptable = array(
'application/pdf', //.pdf
'application/vnd.adobe.xdp+xml', //.pdf
'application/vnd.ms-excel', //.xls
'application/vnd.openxmlformats-officedocument.presentationml.presentation', //.pptx
'application/vnd.openxmlformats-officedocument.presentationml.slideshow', //.ppsx
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', //.xlsx
'application/vnd.openxmlformats-officedocument.spreadsheetml.template', //.xltx
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', //.docx
'application/vnd.openxmlformats-officedocument.wordprocessingml.template', //.dotx
'application/vnd.ms-powerpoint', //.ppt
'application/onenote', //.onetoc
'audio/x-ms-wma', //.wma
'video/x-ms-wmv', //.wmv
'application/msword', //.doc
'application/vnd.ms-xpsdocument', //.xps
'audio/mpeg', //.mpga
'video/mpeg', //.mpeg
'video/mp4', //.mp4
'audio/mp4', //.mp4a
'application/mp4', //.mp4
'application/vnd.oasis.opendocument.presentation', //.odp
'application/vnd.oasis.opendocument.spreadsheet', //.ods
'application/vnd.oasis.opendocument.text', //.odt
'application/vnd.sun.xml.calc', //.sxc
'application/vnd.sun.xml.draw.template', //.std
'application/vnd.sun.xml.writer', //.sxw
'image/vnd.adobe.photoshop', //.psd
'text/plain', //.txt
'text/x-vcard', //.vcf
'application/xml', //.xml
'application/zip', //.zip
'application/x-rar-compressed', //.rar
'video/jpeg',
'text/calendar',
'video/x-flv',
'video/x-msvideo',
'application/x-shockwave-flash',
'image/jpeg',
'image/jpg',
'image/bmp',
'image/gif',
'image/png'
);
if(!in_array($_FILES['cont2']['type'], $acceptable) && !empty($_FILES["cont2"]["type"])) die('<b>File Format not allowed.</b>');
现在的问题是验证过程并不总是有效。当我上传一个.jpg图像,它可以工作,然后我尝试使用PDF,它没有工作。所以我试着通过制作一个简单的
来找出PDF的类型echo $_FILES['cont2']['type'];
并返回应用程序/强制下载。 但是,同一块脚本在另一个脚本文件中使用相同的PDF工作在服务器上。任何想法可能是什么问题以及如何精确解决它?
非常感谢提前