Today in the image upload to verify the MIME value of the image suddenly found that the individual special circumstances Finfo_file get MIME value can not be used directly,
According to the official wording,
$finfo =finfo_open (fileinfo_mime);
$mime =finfo_file ($finfo, $file _path);
Finfo_close ($finfo);
alert ($mime);
This gets the file MIME type of the
But it's not working out today. If you have CharSet set the transport type as a binary stream in a file transfer, it will appear similar to the following:
It can be seen clearly that there are more semicolons and back things behind here charset=binary
If the file MIME value is verified again, even the correct and valid file type cannot be verified, because the MIME value obtained is followed by a portion of the binary file stream string "; Charset=binary "
$file _name = $_files[' imgfile ' [' name '];
$temp _arr = Explode (".", $file _name);
$file _ext = Array_pop ($temp _arr);
$file _ext = Trim ($file _ext);
$file _ext = strtolower ($file _ext);
$_mime=array (' jpg ' =>array (' image/pjpeg ', ' image/jpeg '), ' gif ' =>array (' image/gif '), ' PNG ' =>array (' image/ X-png ', ' image/png '), ' JPEG ' =>array (' image/jpeg ', ' image/pjpeg '));
if (Empty ($mime) | |!in_array ($mime, $_mime[$file _ext])) {
Alert (' Picture MIME type Error! ');
}
therefore need to do under special environmental requirements of the compatibility treatment
The following general method of obtaining the compatibility of the modified MIME type is as follows (note the red portion of the column, which is obtained correctly by getting the MIME value in the correct compatible multi-demand environment):
if (Empty ($mime) && function_exists (' Finfo_open ')) {
$finfo =finfo_open (fileinfo_mime);
$mime =finfo_file ($finfo, $file _path);
//compatible special applications File upload MIME precision verification
$new =preg_match ('/([^;] +);?. *$/', $mime, $match);
if ($new) $mime =trim ($match [1]);
alert ($mime);
In this way, you can correctly obtain the MIME type of the compatible environment to verify the validity of the file mime, and run the result:
http://www.bkjia.com/PHPjc/777566.html www.bkjia.com true http://www.bkjia.com/PHPjc/777566.html techarticle today in the image upload to verify the MIME value of the image is suddenly found in individual special cases Finfo_file obtained MIME value can not be used directly, according to the official wording is $finfo =finfo_open (Fileinf ...