From: Mikael Nordfeldth Date: Thu, 25 Feb 2016 21:31:45 +0000 (+0100) Subject: Try to get mime data before hashing (cpu intensive) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4d17d9533552ea620b83109c550e250a5c236291;p=quix0rs-gnu-social.git Try to get mime data before hashing (cpu intensive) --- diff --git a/plugins/Oembed/OembedPlugin.php b/plugins/Oembed/OembedPlugin.php index 44e4ac9318..196b07d75d 100644 --- a/plugins/Oembed/OembedPlugin.php +++ b/plugins/Oembed/OembedPlugin.php @@ -325,8 +325,10 @@ class OembedPlugin extends Plugin throw new UnsupportedMediaException(_('Image file had impossible geometry (0 width or height)')); } + $ext = File::guessMimeExtension($info['mime']); + // We'll trust sha256 (File::FILEHASH_ALG) not to have collision issues any time soon :) - $filename = hash(File::FILEHASH_ALG, $imgData) . '.' . common_supported_mime_to_ext($info['mime']); + $filename = hash(File::FILEHASH_ALG, $imgData) . ".{$ext}"; $fullpath = File_thumbnail::path($filename); // Write the file to disk. Throw Exception on failure if (!file_exists($fullpath) && file_put_contents($fullpath, $imgData) === false) {