// From CodeIgniter
// We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
- $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
+ $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s[^\/]+)?$/';
/**
* Fileinfo extension - most reliable method
*
*/
if (DIRECTORY_SEPARATOR !== '\\') {
$cmd = 'file --brief --mime '.escapeshellarg($filepath).' 2>&1';
- if (function_exists('exec')) {
+ if (empty($mimetype) && function_exists('exec')) {
/* This might look confusing, as $mime is being populated with all of the output
* when set in the second parameter. However, we only need the last line, which is
* the actual return value of exec(), and as such - it overwrites anything that could
$mimetype = $matches[1];
}
}
- if (function_exists('shell_exec')) {
+ if (empty($mimetype) && function_exists('shell_exec')) {
$mime = @shell_exec($cmd);
if (strlen($mime) > 0) {
$mime = explode("\n", trim($mime));
}
}
}
- if (function_exists('popen')) {
+ if (empty($mimetype) && function_exists('popen')) {
$proc = @popen($cmd, 'r');
if (is_resource($proc)) {
$mime = @fread($proc, 512);
}
}
// Fall back to mime_content_type(), if available (still better than $_FILES[$field]['type'])
- if (function_exists('mime_content_type')) {
+ if (empty($mimetype) && function_exists('mime_content_type')) {
$mimetype = @mime_content_type($filepath);
// It's possible that mime_content_type() returns FALSE or an empty string
if ($mimetype == false && strlen($mimetype) > 0) {
"image.gif" => "image/gif",
"image.jpg" => "image/jpeg",
"image.jpeg" => "image/jpeg",
-
"office.pdf" => "application/pdf",
-
"wordproc.odt" => "application/vnd.oasis.opendocument.text",
"wordproc.ott" => "application/vnd.oasis.opendocument.text-template",
"wordproc.doc" => "application/msword",
"wordproc.docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"wordproc.rtf" => "text/rtf",
-
"spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet",
"spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
- "spreadsheet.xls" => "application/vnd.ms-office", //"application/vnd.ms-excel",
- "spreadsheet.xlt" => "application/vnd.ms-office", //"application/vnd.ms-excel",
- "spreadsheet.xlsx" => "application/octet-stream", //"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
-
+ "spreadsheet.xls" => "application/vnd.ms-excel",
+ "spreadsheet.xlt" => "application/vnd.ms-excel",
+ "spreadsheet.xlsx" =>"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"presentation.odp" => "application/vnd.oasis.opendocument.presentation",
"presentation.otp" => "application/vnd.oasis.opendocument.presentation-template",
"presentation.ppt" => "application/vnd.ms-powerpoint",