Commit 8770d0ae authored by Taylor Otwell's avatar Taylor Otwell

tweaked File::is method.

parent 6f5aca8d
......@@ -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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment