public static function guessExtension($file_path, $reference_name = null, $default = 'bin') {
		if (!$reference_name) {
			$reference_name = basename($file_path);
		}

		if ($extension = pathinfo($reference_name, PATHINFO_EXTENSION) and static::hasExtension($extension)) {
			return strtolower($extension);
		}

		$mime_type = static::getMagicType($file_path);
		if ($mime_type and $extension = static::getExtensionForType($mime_type)) {
			return $extension;
		}

		return $default;
	}
public static function guessExtension($file_path, $reference_name = null, $default = 'bin') {
		if (!$reference_name) {
			$reference_name = basename($file_path);
		}

		if ($extension = pathinfo($reference_name, PATHINFO_EXTENSION) and static::hasExtension($extension)) {
			return strtolower($extension);
		}

		$mime_type = static::getMagicType($file_path);
		if ($mime_type and $extension = static::getExtensionForType($mime_type)) {
			return $extension;
		}

		return $default;
	}
public static function guessExtension ( $ file_path , $ reference_name = null , $ default = 'bin' ) { if ( ! $ reference_name ) { $ reference_name = basename ( $ file_path ) ; } if ( $ extension = pathinfo ( $ reference_name , PATHINFO_EXTENSION ) and static :: hasExtension ( $ extension ) ) { return strtolower ( $ extension ) ; } $ mime_type = static :: getMagicType ( $ file_path ) ; if ( $ mime_type and $ extension = static :: getExtensionForType ( $ mime_type ) ) { return $ extension ; } return $ default ; }
Guess the extension of a given file, first by checking the path then by falling back to magic.

@param string $file_path Relative or absolute path to an existing file.
@param string $reference_name Use this name for detection based on the extension.
@param string $default Default extension.

@return string|null The associated extension or the default if none found.
Guess the extension of a given file first by checking the path then by falling back to magic .