Commit 909df8da by Robert Lyon Committed by Gerrit Code Review

Merge "Pass original filename to file_mime_type()" into 1.6_STABLE

parents b3cd93a0 bfaf9fa0
......@@ -914,7 +914,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
// download. If there's no claimed mimetype, use file_mime_type to make
// a guess, and give each file artefact type access to both the claimed
// and guessed mimetypes.
$data->guess = file_mime_type($path);
$data->guess = file_mime_type($path, "foo.{$data->oldextension}");
if (empty($data->filetype) || $data->filetype == 'application/octet-stream') {
$data->filetype = $data->guess;
......
......@@ -311,9 +311,10 @@ function get_mime_type($file) {
* file extension in the artefact_file_mime_types table
*
* @param string $file The file to check
* @param string $originalfilename The original name of the file (so we can check its extension)
* @return string The mime type of the file
*/
function file_mime_type($file) {
function file_mime_type($file, $originalfilename=false) {
static $mimetypes = null;
if (class_exists('finfo')) {
......@@ -357,7 +358,12 @@ function file_mime_type($file) {
// 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.
$basename = basename($file);
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');
......
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