PMA\libraries\Util::getCompressionMimeType PHP Method

getCompressionMimeType() public static method

Reads the file, detects the compression MIME type, closes the file and returns the MIME type
public static getCompressionMimeType ( resource $file ) : string
$file resource the file handle
return string the MIME type for compression, or 'none'
    public static function getCompressionMimeType($file)
    {
        $test = fread($file, 4);
        $len = strlen($test);
        fclose($file);
        if ($len >= 2 && $test[0] == chr(31) && $test[1] == chr(139)) {
            return 'application/gzip';
        }
        if ($len >= 3 && substr($test, 0, 3) == 'BZh') {
            return 'application/bzip2';
        }
        if ($len >= 4 && $test == "PK") {
            return 'application/zip';
        }
        return 'none';
    }

Usage Example

コード例 #1
0
ファイル: import.lib.php プロジェクト: netroby/phpmyadmin
/**
 * Detects what compression the file uses
 *
 * @param string $filepath filename to check
 *
 * @return string MIME type of compression, none for none
 * @access public
 */
function PMA_detectCompression($filepath)
{
    $file = @fopen($filepath, 'rb');
    if (!$file) {
        return false;
    }
    return PMA\libraries\Util::getCompressionMimeType($file);
}
All Usage Examples Of PMA\libraries\Util::getCompressionMimeType
Util