]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Only accept filenames for existing files in getUploadedFileType
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 8 Mar 2014 00:42:24 +0000 (01:42 +0100)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 8 Mar 2014 00:42:24 +0000 (01:42 +0100)
Getting metadata from filehandles just meant duplicating work

lib/mediafile.php
tests/MediaFileTest.php

index ad696ccca6a02df759e51f584094ed2c98b6f7bc..e01d2eaeabc9b896be6f301288c5d125daceee17 100644 (file)
@@ -252,7 +252,7 @@ class MediaFile
 
         File::respectsQuota($scoped, filesize($stream['uri']));
 
-        $mimetype = MediaFile::getUploadedFileType($fh);
+        $mimetype = MediaFile::getUploadedFileType($stream['uri']);
 
         $filename = File::filename($scoped, "email", $mimetype);
 
@@ -304,19 +304,8 @@ class MediaFile
         // are unambiguous for most image files, but nearly useless
         // for office document formats.
 
-        if (is_string($f)) {
-
-            // assuming a filename
-
-            $filetype = MIME_Type::autoDetect($f);
-
-        } else {
-
-            // assuming a filehandle
-
-            $stream  = stream_get_meta_data($f);
-            $filetype = MIME_Type::autoDetect($stream['uri']);
-        }
+        // We only accept filenames to existing files
+        $filetype = MIME_Type::autoDetect($f);
 
         // The content-based sources for MIME_Type::autoDetect()
         // are wildly unreliable for office-type documents. If we've
index b1891574e2fca6f0e6c0831c83a72cffede27191..6d96497c5b9100151c435f91aacec372266402a9 100644 (file)
@@ -51,7 +51,8 @@ class MediaFileTest extends PHPUnit_Framework_TestCase
         $tmp = tmpfile();
         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);
     }