protected function detectFileExtension($path) {
		static $type, $finfo, $extTable;
		if (!$type) {
			$keys = array_keys($this->volumes);
			$volume = $this->volumes[$keys[0]];
			$extTable = array_flip(array_unique($volume->getMimeTable()));
			
			if (class_exists('finfo')) {
				$tmpFileInfo = @explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
			} else {
				$tmpFileInfo = false;
			}
			$regexp = '/text\/x\-(php|c\+\+)/';
			if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) {
				$type = 'finfo';
				$finfo = finfo_open(FILEINFO_MIME);
			} elseif (function_exists('mime_content_type')
					&& preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) {
				$type = 'mime_content_type';
			} elseif (function_exists('getimagesize')) {
				$type = 'getimagesize';
			} else {
				$type = 'none';
			}
		}
		
		$mime = '';
		if ($type === 'finfo') {
			$mime = @finfo_file($finfo, $path);
		} elseif ($type === 'mime_content_type') {
			$mime = mime_content_type($path);
		} elseif ($type === 'getimagesize') {
			if ($img = @getimagesize($path)) {
				$mime = $img['mime'];
			}
		}
		
		if ($mime) {
			$mime = explode(';', $mime);
			$mime = trim($mime[0]);
			
			if (in_array($mime, array('application/x-empty', 'inode/x-empty'))) {
				// finfo return this mime for empty files
				$mime = 'text/plain';
			} elseif ($mime == 'application/x-zip') {
				// http://elrte.org/redmine/issues/163
				$mime = 'application/zip';
			}
		}
		
		return ($mime && isset($extTable[$mime]))? ('.' . $extTable[$mime]) : '';
	}
protected function detectFileExtension($path) {
		static $type, $finfo, $extTable;
		if (!$type) {
			$keys = array_keys($this->volumes);
			$volume = $this->volumes[$keys[0]];
			$extTable = array_flip(array_unique($volume->getMimeTable()));
			
			if (class_exists('finfo')) {
				$tmpFileInfo = @explode(';', @finfo_file(finfo_open(FILEINFO_MIME), __FILE__));
			} else {
				$tmpFileInfo = false;
			}
			$regexp = '/text\/x\-(php|c\+\+)/';
			if ($tmpFileInfo && preg_match($regexp, array_shift($tmpFileInfo))) {
				$type = 'finfo';
				$finfo = finfo_open(FILEINFO_MIME);
			} elseif (function_exists('mime_content_type')
					&& preg_match($regexp, array_shift(explode(';', mime_content_type(__FILE__))))) {
				$type = 'mime_content_type';
			} elseif (function_exists('getimagesize')) {
				$type = 'getimagesize';
			} else {
				$type = 'none';
			}
		}
		
		$mime = '';
		if ($type === 'finfo') {
			$mime = @finfo_file($finfo, $path);
		} elseif ($type === 'mime_content_type') {
			$mime = mime_content_type($path);
		} elseif ($type === 'getimagesize') {
			if ($img = @getimagesize($path)) {
				$mime = $img['mime'];
			}
		}
		
		if ($mime) {
			$mime = explode(';', $mime);
			$mime = trim($mime[0]);
			
			if (in_array($mime, array('application/x-empty', 'inode/x-empty'))) {
				// finfo return this mime for empty files
				$mime = 'text/plain';
			} elseif ($mime == 'application/x-zip') {
				// http://elrte.org/redmine/issues/163
				$mime = 'application/zip';
			}
		}
		
		return ($mime && isset($extTable[$mime]))? ('.' . $extTable[$mime]) : '';
	}
protected function detectFileExtension ( $ path ) { static $ type , $ finfo , $ extTable ; if ( ! $ type ) { $ keys = array_keys ( $ this -> volumes ) ; $ volume = $ this -> volumes [ $ keys [ 0 ] ] ; $ extTable = array_flip ( array_unique ( $ volume -> getMimeTable ( ) ) ) ; if ( class_exists ( 'finfo' ) ) { $ tmpFileInfo = @ explode ( ';' , @ finfo_file ( finfo_open ( FILEINFO_MIME ) , __FILE__ ) ) ; } else { $ tmpFileInfo = false ; } $ regexp = '/text\/x\-(php|c\+\+)/' ; if ( $ tmpFileInfo && preg_match ( $ regexp , array_shift ( $ tmpFileInfo ) ) ) { $ type = 'finfo' ; $ finfo = finfo_open ( FILEINFO_MIME ) ; } elseif ( function_exists ( 'mime_content_type' ) && preg_match ( $ regexp , array_shift ( explode ( ';' , mime_content_type ( __FILE__ ) ) ) ) ) { $ type = 'mime_content_type' ; } elseif ( function_exists ( 'getimagesize' ) ) { $ type = 'getimagesize' ; } else { $ type = 'none' ; } } $ mime = '' ; if ( $ type === 'finfo' ) { $ mime = @ finfo_file ( $ finfo , $ path ) ; } elseif ( $ type === 'mime_content_type' ) { $ mime = mime_content_type ( $ path ) ; } elseif ( $ type === 'getimagesize' ) { if ( $ img = @ getimagesize ( $ path ) ) { $ mime = $ img [ 'mime' ] ; } } if ( $ mime ) { $ mime = explode ( ';' , $ mime ) ; $ mime = trim ( $ mime [ 0 ] ) ; if ( in_array ( $ mime , array ( 'application/x-empty' , 'inode/x-empty' ) ) ) { // finfo return this mime for empty files $ mime = 'text/plain' ; } elseif ( $ mime == 'application/x-zip' ) { // http://elrte.org/redmine/issues/163 $ mime = 'application/zip' ; } } return ( $ mime && isset ( $ extTable [ $ mime ] ) ) ? ( '.' . $ extTable [ $ mime ] ) : '' ; }
Detect file type extension by local path

@param  string $path Local path
@return string file type extension with dot
@author Naoki Sawada
Detect file type extension by local path