tweaked File::is method.
This commit is contained in:
@@ -136,25 +136,6 @@ class File {
|
||||
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 @@ class File {
|
||||
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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user