Allow upload type part code
$uptypes =array (//Upload file type list
' Image/gif ', ' image/jpg ', ' image/jpeg ', ' image/pjpeg ', ' image/png ', ' Application/msword ', ' application/vnd.ms-excel ' ,
' Image/bmp ', ' text/plain ', ' application/octet-stream ', ' image/x-png ', ' application/x-shockwave-flash ', ' audio/mpeg ' , ' audio/x-ms-wma ',
' Application/x-zip-compressed '
);
Determine the File Type section
if (!in_array ($_files["Upfile" ["type"], $uptypes))
Check file types
{
echo "<font color= ' red ' > cannot upload this type of file! </font> ";
Exit
}
My intention is to allow files such as RAR upload, but when testing, bat,exe and other formats can be uploaded, I tested a bit, this kind of file is also $_files["upfile" ["type"] is ' application/octet-stream ', So I can upload it.
At present I want to allow RAR upload, but also prohibit bat other format file upload what to do?
Code to resolve:
$uptypes =array (//Upload file type list
' gif ', ' jpg ', ' jpeg ', ' png ', ' Doc ', ' xls ',
' BMP ', ' txt ', ' rar ', ' swf ', ' mp3 ', ' wma ',
' Zip '
);
$test =$_files["Upfile" ["Name"];
function Getfileext ($file _name)
{
while ($dot = Strpos ($file _name, "."))
{
$file _name = substr ($file _name, $dot + 1);
}
return $file _name;
}
$test 1= strtolower (Getfileext ($test));
if (!in_array ($test 1, $uptypes))
Check file types
{
echo "<font color= ' red ' > cannot upload this type of file! </font> ";
Exit ();
}
Summary: The direct check file extension is used $_files["Upfile" ["name"], rather than using this $_files["Upfile" ["type"]; the type of file to limit.
Upload file Format Control confusion (Application/octet-stream not limit the bat and other format upload) problem solving