Commit cf7e2c82 by Robert Lyon Committed by Gerrit Code Review

Merge "Allowing the .zip files to be detected by file extension (Bug #1302251)" into 1.6_STABLE

parents fd9f88a8 4668f108
......@@ -317,6 +317,27 @@ function get_mime_type($file) {
function file_mime_type($file, $originalfilename=false) {
static $mimetypes = null;
// Try the filename extension in case it's a file that Mahara
// cares about. For now, use the artefact_file_mime_types table,
// even though it's in a plugin and the description column doesn't
// really contain filename extensions.
if ($originalfilename) {
$basename = $originalfilename;
}
else {
$basename = basename($file);
}
if (strpos($basename, '.', 1)) {
if (is_null($mimetypes)) {
$mimetypes = get_records_assoc('artefact_file_mime_types', '', '', '', 'description,mimetype');
}
$ext = strtolower(array_pop(explode('.', $basename)));
if (isset($mimetypes[$ext])) {
return $mimetypes[$ext]->mimetype;
}
}
// Try detecting it with the magic.mgc file
if (get_config('pathtomagicdb') !== null) {
// Manually specified magicdb path in config.php
$magicfile = get_config('pathtomagicdb');
......@@ -346,30 +367,10 @@ function file_mime_type($file, $originalfilename=false) {
$type = mime_content_type($file);
}
if (!empty($type) && $type != 'application/octet-stream') {
if (!empty($type)) {
return $type;
}
// Try the filename extension in case it's a file that Mahara
// cares about. For now, use the artefact_file_mime_types table,
// even though it's in a plugin and the description column doesn't
// really contain filename extensions.
if ($originalfilename) {
$basename = $originalfilename;
}
else {
$basename = basename($file);
}
if (strpos($basename, '.', 1)) {
if (is_null($mimetypes)) {
$mimetypes = get_records_assoc('artefact_file_mime_types', '', '', '', 'description,mimetype');
}
$ext = strtolower(array_pop(explode('.', $basename)));
if (isset($mimetypes[$ext])) {
return $mimetypes[$ext]->mimetype;
}
}
return 'application/octet-stream';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment