Commented on the mime extension matching regexp

This commit is contained in:
Mikael Nordfeldth 2016-02-25 22:32:07 +01:00
parent 4d17d95335
commit aeb2e282db
1 changed files with 2 additions and 3 deletions

View File

@ -264,7 +264,6 @@ class File extends Managed_DataObject
*/ */
static function guessMimeExtension($mimetype, $filename=null) static function guessMimeExtension($mimetype, $filename=null)
{ {
$ext = null;
try { try {
// first see if we know the extension for our mimetype // first see if we know the extension for our mimetype
$ext = common_supported_mime_to_ext($mimetype); $ext = common_supported_mime_to_ext($mimetype);
@ -301,11 +300,11 @@ class File extends Managed_DataObject
// If nothing else has given us a result, try to extract it from // If nothing else has given us a result, try to extract it from
// the mimetype value (this turns .jpg to .jpeg for example...) // the mimetype value (this turns .jpg to .jpeg for example...)
$matches = array(); $matches = array();
// FIXME: try to build a regexp that will get jpeg from image/jpeg as well as json from application/jrd+json
if (!preg_match('/\/([a-z0-9]+)/', mb_strtolower($mimetype), $matches)) { if (!preg_match('/\/([a-z0-9]+)/', mb_strtolower($mimetype), $matches)) {
throw new Exception('Malformed mimetype: '.$mimetype); throw new Exception('Malformed mimetype: '.$mimetype);
} }
$ext = mb_strtolower($matches[1]); return mb_strtolower($matches[1]);
return $ext;
} }
/** /**