Only accept filenames for existing files in getUploadedFileType
Getting metadata from filehandles just meant duplicating work
This commit is contained in:
parent
5c34369460
commit
6f6065e5e9
@ -252,7 +252,7 @@ class MediaFile
|
|||||||
|
|
||||||
File::respectsQuota($scoped, filesize($stream['uri']));
|
File::respectsQuota($scoped, filesize($stream['uri']));
|
||||||
|
|
||||||
$mimetype = MediaFile::getUploadedFileType($fh);
|
$mimetype = MediaFile::getUploadedFileType($stream['uri']);
|
||||||
|
|
||||||
$filename = File::filename($scoped, "email", $mimetype);
|
$filename = File::filename($scoped, "email", $mimetype);
|
||||||
|
|
||||||
@ -304,20 +304,9 @@ class MediaFile
|
|||||||
// are unambiguous for most image files, but nearly useless
|
// are unambiguous for most image files, but nearly useless
|
||||||
// for office document formats.
|
// for office document formats.
|
||||||
|
|
||||||
if (is_string($f)) {
|
// We only accept filenames to existing files
|
||||||
|
|
||||||
// assuming a filename
|
|
||||||
|
|
||||||
$filetype = MIME_Type::autoDetect($f);
|
$filetype = MIME_Type::autoDetect($f);
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// assuming a filehandle
|
|
||||||
|
|
||||||
$stream = stream_get_meta_data($f);
|
|
||||||
$filetype = MIME_Type::autoDetect($stream['uri']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The content-based sources for MIME_Type::autoDetect()
|
// The content-based sources for MIME_Type::autoDetect()
|
||||||
// are wildly unreliable for office-type documents. If we've
|
// are wildly unreliable for office-type documents. If we've
|
||||||
// gotten an unclear reponse back or just couldn't identify it,
|
// gotten an unclear reponse back or just couldn't identify it,
|
||||||
|
@ -51,7 +51,8 @@ class MediaFileTest extends PHPUnit_Framework_TestCase
|
|||||||
$tmp = tmpfile();
|
$tmp = tmpfile();
|
||||||
fwrite($tmp, file_get_contents($filename));
|
fwrite($tmp, file_get_contents($filename));
|
||||||
|
|
||||||
$type = MediaFile::getUploadedFileType($tmp, basename($filename));
|
$tmp_metadata = stream_get_meta_data($tmp);
|
||||||
|
$type = MediaFile::getUploadedFileType($tmp_metadata['uri'], basename($filename));
|
||||||
$this->assertEquals($expectedType, $type);
|
$this->assertEquals($expectedType, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user