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' |
/** * 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); }
/** * Detects what compression the file uses * * @todo move file read part into readChunk() or getChunk() * @todo add support for compression plugins * @access protected * @return string|false false on error, otherwise string MIME type of * compression, none for none */ protected function detectCompression() { // suppress warnings from being displayed, but not from being logged // f.e. any file access outside of open_basedir will issue a warning ob_start(); $file = fopen($this->getName(), 'rb'); ob_end_clean(); if (!$file) { $this->_error_message = Message::error(__('File could not be read!')); return false; } /** * @todo * get registered plugins for file compression foreach (PMA_getPlugins($type = 'compression') as $plugin) { if ($plugin['classname']::canHandle($this->getName())) { $this->setCompressionPlugin($plugin); break; } } */ $this->_compression = Util::getCompressionMimeType($file); return $this->_compression; }