mirror of
				https://git.code.sf.net/p/seeddms/code
				synced 2025-10-30 20:51:22 +00:00 
			
		
		
		
	add method mimetype()
This commit is contained in:
		
							parent
							
								
									0e8f9c5164
								
							
						
					
					
						commit
						7716d3ad54
					
				|  | @ -80,8 +80,37 @@ class SeedDMS_Core_File { | |||
| 	} /* }}} */ | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param $size | ||||
| 	 * @param array $sizes | ||||
| 	 * Return the mimetype of a given file | ||||
| 	 * | ||||
| 	 * This method uses finfo to determine the mimetype | ||||
| 	 * but will correct some mimetypes which are | ||||
| 	 * not propperly determined or could be more specific, e.g. text/plain | ||||
| 	 * when it is actually text/markdown. In thoses cases | ||||
| 	 * the file extension will be taken into account. | ||||
| 	 * | ||||
| 	 * @param string $filename name of file on disc | ||||
| 	 * @return string mimetype | ||||
| 	 */ | ||||
| 	static function mimetype($filename) { /* {{{ */ | ||||
| 		$finfo = finfo_open(FILEINFO_MIME_TYPE); | ||||
| 		$mimetype = finfo_file($finfo, $filename); | ||||
| 
 | ||||
| 		switch($mimetype) { | ||||
| 		case 'application/octet-stream': | ||||
| 		case 'text/plain': | ||||
| 			$lastDotIndex = strrpos($filename, "."); | ||||
| 			if($lastDotIndex === false) $fileType = "."; | ||||
| 			else $fileType = substr($filename, $lastDotIndex); | ||||
| 			if($fileType == '.md') | ||||
| 				$mimetype = 'text/markdown'; | ||||
| 			break; | ||||
| 		} | ||||
| 		return $mimetype; | ||||
| 	} /* }}} */ | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param integer $size | ||||
| 	 * @param array $sizes list of units for 10^0, 10^3, 10^6, ..., 10^(n*3) bytes | ||||
| 	 * @return string | ||||
| 	 */ | ||||
| 	static function format_filesize($size, $sizes = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')) { /* {{{ */ | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Uwe Steinmann
						Uwe Steinmann