add function get_extension()

returns file extension by mimetype
This commit is contained in:
Uwe Steinmann 2015-06-12 08:59:05 +02:00
parent 212e345cdc
commit 561b8d81ee

View File

@ -442,4 +442,46 @@ function checkQuota($user) { /* {{{ */
return ($quota - $user->getUsedDiskSpace());
} /* }}} */
/**
* Return file extension for a give mimetype
*
* @param string $mimetype Mime-Type
* @return string file extension including leading dot
*/
function get_extension($mimetype) { /* {{{ */
if(empty($mimetype)) return false;
switch($mimetype) {
case 'image/bmp': return '.bmp';
case 'image/cis-cod': return '.cod';
case 'image/gif': return '.gif';
case 'image/ief': return '.ief';
case 'image/jpeg': return '.jpg';
case 'image/pipeg': return '.jfif';
case 'image/tiff': return '.tif';
case 'image/x-cmu-raster': return '.ras';
case 'image/x-cmx': return '.cmx';
case 'image/x-icon': return '.ico';
case 'image/x-portable-anymap': return '.pnm';
case 'image/x-portable-bitmap': return '.pbm';
case 'image/x-portable-graymap': return '.pgm';
case 'image/x-portable-pixmap': return '.ppm';
case 'image/x-rgb': return '.rgb';
case 'image/x-xbitmap': return '.xbm';
case 'image/x-xpixmap': return '.xpm';
case 'image/x-xwindowdump': return '.xwd';
case 'image/png': return '.png';
case 'image/x-jps': return '.jps';
case 'image/x-freehand': return '.fh';
case 'image/svg+xml': return '.svg';
case 'application/zip': return '.zip';
case 'application/x-rar': return '.rar';
case 'application/pdf': return '.pdf';
case 'application/postscript': return '.ps';
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': return '.docx';
case 'text/plain': return '.txt';
case 'text/csv': return '.csv';
default: return false;
}
} /* }}} */
?>