Commit bfaf9fa0 by Aaron Wells

Pass original filename to file_mime_type()

Bug 1249858: When being called for file uploads, file_mime_type() is getting the PHP temp upload file's filename, and so the attempt to check the file extension is always unsuccessful because those temp file names are gibberish Change-Id: I631ca8c80316919b6aefc9712b68017d752ba942
parent 30d1409c
......@@ -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