* Etemplate - Don't trust browsers mime if we don't have to - fixes incorrect mime types and Resources rejecting pictures

This commit is contained in:
nathangray 2018-01-30 09:14:37 -07:00
parent 564a4cab5d
commit f4e2230191

View File

@ -147,10 +147,15 @@ class File extends Etemplate\Widget
} }
if ($file['error'] == UPLOAD_ERR_OK && trim($file['name']) != '' && $file['size'] > 0 && is_uploaded_file($file['tmp_name'])) { if ($file['error'] == UPLOAD_ERR_OK && trim($file['name']) != '' && $file['size'] > 0 && is_uploaded_file($file['tmp_name'])) {
// Don't trust what the browser tells us for mime
if(function_exists('mime_content_type'))
{
$file['type'] = $type = mime_content_type($file['tmp_name']);
}
// Mime check // Mime check
if($mime) if($mime)
{ {
$type = $file['type'];
$is_preg = $mime[0] == '/'; $is_preg = $mime[0] == '/';
if (!$is_preg && strcasecmp($mime,$type) || if (!$is_preg && strcasecmp($mime,$type) ||
$is_preg && !preg_match($mime,$type)) $is_preg && !preg_match($mime,$type))