mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-03-12 00:45:34 +00:00
add new function getMimeType()
This commit is contained in:
parent
8e47c444b2
commit
aa18d3f883
|
@ -395,6 +395,34 @@ function getFilenameByDocname($content) { /* {{{ */
|
|||
return mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
|
||||
} /* }}} */
|
||||
|
||||
/**
|
||||
* Return the mimetype of a given file
|
||||
*
|
||||
* This functions uses finfo but will correct some mimetypes which are
|
||||
* not propperly determined or could be more specific, e.g. text/plain
|
||||
* which 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
|
||||
*/
|
||||
function getMimeType($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($name, $lastDotIndex);
|
||||
if($fileType == '.md')
|
||||
$mimetype = 'text/markdown';
|
||||
break;
|
||||
}
|
||||
return $mimetype;
|
||||
} /* }}} */
|
||||
|
||||
function getLogger($prefix='', $mask=PEAR_LOG_INFO) { /* {{{ */
|
||||
global $settings;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user