tweaked File::is method.
This commit is contained in:
parent
6f5aca8d48
commit
8770d0aea1
|
@ -136,25 +136,6 @@ public static function append($path, $data)
|
|||
return file_put_contents($path, $data, LOCK_EX | FILE_APPEND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a file is a given type.
|
||||
*
|
||||
* The Fileinfo PHP extension will be used to determine the MIME
|
||||
* type of the file. Any extension in the File::$mimes array may
|
||||
* be passed as a type.
|
||||
*/
|
||||
public static function is($extension, $path)
|
||||
{
|
||||
if ( ! array_key_exists($extension, static::$mimes))
|
||||
{
|
||||
throw new \Exception("File extension [$extension] is unknown. Cannot determine file type.");
|
||||
}
|
||||
|
||||
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
|
||||
|
||||
return (is_array(static::$mimes[$extension])) ? in_array($mime, static::$mimes[$extension]) : $mime === static::$mimes[$extension];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the extension from a file path.
|
||||
*
|
||||
|
@ -183,6 +164,25 @@ public static function mime($extension, $default = 'application/octet-stream')
|
|||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a file is a given type.
|
||||
*
|
||||
* The Fileinfo PHP extension will be used to determine the MIME
|
||||
* type of the file. Any extension in the File::$mimes array may
|
||||
* be passed as a type.
|
||||
*/
|
||||
public static function is($extension, $path)
|
||||
{
|
||||
if ( ! array_key_exists($extension, static::$mimes))
|
||||
{
|
||||
throw new \Exception("File extension [$extension] is unknown. Cannot determine file type.");
|
||||
}
|
||||
|
||||
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
|
||||
|
||||
return (is_array(static::$mimes[$extension])) ? in_array($mime, static::$mimes[$extension]) : $mime === static::$mimes[$extension];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a response that will force a file to be downloaded.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue