Commit 4284106c authored by Robert Lyon's avatar Robert Lyon

Prefer fileinfo detected mimetype over browser-supplied mimetype (Bug #1249858)

Browsers can get the their mimetypes for certain things mixed up if
they visit badly written websites. So we should trust magicdb over
what the browser tells us.

Change-Id: I477580d55a70f7e2d03385897a6ec02166506908
Signed-off-by: Robert Lyon's avatarRobert Lyon <>
parent 8e3d1425
......@@ -908,15 +908,12 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return new ArtefactTypeImage(0, $data);
// If $data->filetype is set here, it's probably the claim made by the
// browser during upload or by a Leap2a file. Generally we believe this
// claim, because it gives better results when serving the file on
// 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, "foo.{$data->oldextension}");
if (empty($data->filetype) || $data->filetype == 'application/octet-stream') {
// The guessed mimetype tends to be more accurate than what the browser tells us.
// Use the guess, unless it failed to find a match.
// But if it failed to find a match *and* there is no browser-supplied mimetype,
// then just use the guess.
if ($data->guess != 'application/octet-stream' || empty($data->filetype)) {
$data->filetype = $data->guess;
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