Pimcore\File::getFileExtension PHP Method

getFileExtension() public static method

public static getFileExtension ( $name ) : string
$name
return string
    public static function getFileExtension($name)
    {
        $name = strtolower($name);
        $parts = explode(".", $name);
        if (count($parts) > 1) {
            return strtolower($parts[count($parts) - 1]);
        }
        return "";
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param $file
  * @param null $filename
  * @return mixed|string
  * @throws \Exception
  */
 public static function detect($file, $filename = null)
 {
     if (!file_exists($file)) {
         throw new \Exception("File " . $file . " doesn't exist");
     }
     if (!$filename) {
         $filename = basename($file);
     }
     // check for an extension mapping first
     if ($filename) {
         $extension = \Pimcore\File::getFileExtension($filename);
         if (array_key_exists($extension, self::$extensionMapping)) {
             return self::$extensionMapping[$extension];
         }
     }
     // check with fileinfo, if there's no extension mapping
     $finfo = finfo_open(FILEINFO_MIME);
     $type = finfo_file($finfo, $file);
     finfo_close($finfo);
     if ($type !== false && !empty($type)) {
         if (strstr($type, ';')) {
             $type = substr($type, 0, strpos($type, ';'));
         }
         return $type;
     }
     // return default mime-type if we're unable to detect it
     return "application/octet-stream";
 }
All Usage Examples Of Pimcore\File::getFileExtension