Hello,
Today, I was trying to upload a CVS file using the Upload Class on one of my website and kept getting a filetype error message, although the MIME type of my file (text/csv) was properly configured in the accepted types.
After some investigation, I have discovered that the following block of code from the Upload class was returning a wrong MIME type (text/x-c++) :
Code:
if (function_exists('finfo_file'))
{
$finfo = @finfo_open(FILEINFO_MIME);
if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system
{
$mime = @finfo_file($finfo, $file['tmp_name']);
finfo_close($finfo);
/* According to the comments section of the PHP manual page,
* it is possible that this function returns an empty string
* for some files (e.g. if they don't exist in the magic MIME database)
*/
if (is_string($mime) && preg_match($regexp, $mime, $matches))
{
$this->file_type = $matches[1];
return;
}
}
}
Further googleing indicates that finfo_file may return inappropriate mime types.
I had no other solution but to disable this method of detection.
Any possible workaround?
Thanks in advance !