note 106198 added to function.finfo-file
| From: | AUC at osu1 dot php dot net | Date: | Tue, 18 Oct 2011 09:44:16 +0000 |
| Subject: | note 106198 added to function.finfo-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183953@lists.php.net to get a copy of this message | ||
function file2mimetype($file)
{
$mime_types = array(
// text
'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
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'dot' => 'application/msword',
// ms office 2007
'docx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'dotx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
'xls' => 'application/vnd.ms-excel',
'xlt' => 'application/vnd.ms-excel',
'xla' => 'application/vnd.ms-excel',
'xlsx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xltx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
'ppt' => 'application/vnd.ms-powerpoint',
'pot' => 'application/vnd.ms-powerpoint',
'pps' => 'application/vnd.ms-powerpoint',
'ppa' => 'application/vnd.ms-powerpoint',
'pptx' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'potx' =>
'application/vnd.openxmlformats-officedocument.presentationml.template',
'ppsx' =>
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);
$ext = strtolower(array_pop(explode('.',$file)));
if(array_key_exists($ext,$mime_types))
{// version 'en dur'
return $mime_types[$ext];
}
elseif (function_exists('finfo_open'))
{// PHP >= 5.3.0
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo,$file);
finfo_close($finfo);
return $mimetype;
}
elseif (function_exists('mime_content_type'))
{// PHP >= 4.3.0 (obselete)
return mime_content_type($file);
}
else
{
return 'application/octet-stream';
}
}
----
Server IP: 195.221.21.36
Probable Submitter: 81.80.208.137
----
Manual Page -- http://www.php.net/manual/en/function.finfo-file.php
Edit -- https://master.php.net/note/edit/106198
Del: integrated -- https://master.php.net/note/delete/106198/integrated
Del: useless -- https://master.php.net/note/delete/106198/useless
Del: bad code -- https://master.php.net/note/delete/106198/bad+code
Del: spam -- https://master.php.net/note/delete/106198/spam
Del: non-english -- https://master.php.net/note/delete/106198/non-english
Del: in docs -- https://master.php.net/note/delete/106198/in+docs
Del: other reasons-- https://master.php.net/note/delete/106198
Reject -- https://master.php.net/note/reject/106198
Search -- https://master.php.net/manage/user-notes.php