note 112936 added to function.finfo-file
| From: | da_kooz at hotmail dot com | Date: | Thu, 08 Aug 2013 20:13:58 +0000 |
| Subject: | note 112936 added to function.finfo-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195917@lists.php.net to get a copy of this message | ||
Here is an wrapper that will properly identify Microsoft Office 2007 documents. It's trivial
and straightforward to use, edit, and to add more file extentions/mimetypes.
<?php
function get_mimetype($filepath) {
if(!preg_match('/\.[^\/\\\\]+$/',$filepath)) {
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filepath);
}
switch(strtolower(preg_replace('/^.*\./','',$filepath))) {
// START MS Office 2007 Docs
case 'docx':
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
case 'docm':
return 'application/vnd.ms-word.document.macroEnabled.12';
case 'dotx':
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.template';
case 'dotm':
return 'application/vnd.ms-word.template.macroEnabled.12';
case 'xlsx':
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
case 'xlsm':
return 'application/vnd.ms-excel.sheet.macroEnabled.12';
case 'xltx':
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
case 'xltm':
return 'application/vnd.ms-excel.template.macroEnabled.12';
case 'xlsb':
return 'application/vnd.ms-excel.sheet.binary.macroEnabled.12';
case 'xlam':
return 'application/vnd.ms-excel.addin.macroEnabled.12';
case 'pptx':
return 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
case 'pptm':
return 'application/vnd.ms-powerpoint.presentation.macroEnabled.12';
case 'ppsx':
return 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
case 'ppsm':
return 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12';
case 'potx':
return 'application/vnd.openxmlformats-officedocument.presentationml.template';
case 'potm':
return 'application/vnd.ms-powerpoint.template.macroEnabled.12';
case 'ppam':
return 'application/vnd.ms-powerpoint.addin.macroEnabled.12';
case 'sldx':
return 'application/vnd.openxmlformats-officedocument.presentationml.slide';
case 'sldm':
return 'application/vnd.ms-powerpoint.slide.macroEnabled.12';
case 'one':
return 'application/msonenote';
case 'onetoc2':
return 'application/msonenote';
case 'onetmp':
return 'application/msonenote';
case 'onepkg':
return 'application/msonenote';
case 'thmx':
return 'application/vnd.ms-officetheme';
//END MS Office 2007 Docs
}
return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $filepath);
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 207.67.108.200
----
Manual Page -- http://php.net/manual/en/function.finfo-file.php
Edit -- https://master.php.net/note/edit/112936
Del: integrated -- https://master.php.net/note/delete/112936/integrated
Del: useless -- https://master.php.net/note/delete/112936/useless
Del: bad code -- https://master.php.net/note/delete/112936/bad+code
Del: spam -- https://master.php.net/note/delete/112936/spam
Del: non-english -- https://master.php.net/note/delete/112936/non-english
Del: in docs -- https://master.php.net/note/delete/112936/in+docs
Del: other reasons-- https://master.php.net/note/delete/112936
Reject -- https://master.php.net/note/reject/112936
Search -- https://master.php.net/manage/user-notes.php