F::type PHP Method

type() public static method

Categorize the file
public static type ( string $file ) : string
$file string Either the file path or extension
return string
    public static function type($file)
    {
        $length = strlen($file);
        if ($length >= 2 && $length <= 4) {
            // use the file name as extension
            $extension = $file;
        } else {
            // get the extension from the filename
            $extension = pathinfo($file, PATHINFO_EXTENSION);
        }
        if (empty($extension)) {
            // detect the mime type first to get the most reliable extension
            $mime = static::mime($file);
            $extension = static::mimeToExtension($mime);
        }
        // sanitize extension
        $extension = strtolower($extension);
        foreach (static::$types as $type => $extensions) {
            if (in_array($extension, $extensions)) {
                return $type;
            }
        }
        return null;
    }