note 101541 added to function.mime-content-type
| From: | Dmitri at osu1 dot php dot net | Date: | Thu, 23 Dec 2010 12:05:51 +0000 |
| Subject: | note 101541 added to function.mime-content-type | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175160@lists.php.net to get a copy of this message | ||
I've extended the code a bit (MS Office 2007 and 2010 mime-types added) and replaced all
whitespaces by tabs. Just a little tweak. ;)
<?php
if(!function_exists('mime_content_type')) {
function mime_content_type($filename) {
$mime_types = array(
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
// ms office
//IMPORTANT NOTE: REMOVE THE WHITESPACES AND /*SNIP*/
//PHP.NET DOESNT ACCEPT SUCH LONG LINES IN THEIR COMMENTS
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats- /*SNIP*/
officedocument.wordprocessingml.document',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'xlsx' => 'application/vnd.openxmlformats- /*SNIP*/
officedocument.spreadsheetml.sheet',
'ppt' => 'application/vnd.ms-powerpoint',
'pptx' => 'application/vnd.openxmlformats- /*SNIP*/
officedocument.presentationml.presentation',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);
$ext = strtolower(array_pop(explode('.',$filename)));
if (array_key_exists($ext, $mime_types)) {
return $mime_types[$ext];
}
elseif (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
}
else {
return 'application/octet-stream';
}
}
}
?>
----
Server IP: 83.137.20.135
Probable Submitter: 195.241.174.225
----
Manual Page -- http://www.php.net/manual/en/function.mime-content-type.php
Edit -- https://master.php.net/note/edit/101541
Del: integrated -- https://master.php.net/note/delete/101541/integrated
Del: useless -- https://master.php.net/note/delete/101541/useless
Del: bad code -- https://master.php.net/note/delete/101541/bad+code
Del: spam -- https://master.php.net/note/delete/101541/spam
Del: non-english -- https://master.php.net/note/delete/101541/non-english
Del: in docs -- https://master.php.net/note/delete/101541/in+docs
Del: other reasons-- https://master.php.net/note/delete/101541
Reject -- https://master.php.net/note/reject/101541
Search -- https://master.php.net/manage/user-notes.php