php finfo,PHP: finfo_file - Manual

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.

if(!preg_match('/\.[^\/\\\\]+$/',$filepath)) {

returnfinfo_file(finfo_open(FILEINFO_MIME_TYPE),$filepath);

}

switch(strtolower(preg_replace('/^.*\./','',$filepath))) {// START MS Office 2007 Docscase'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}

returnfinfo_file(finfo_open(FILEINFO_MIME_TYPE),$filepath);

}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值