PHP xls、xlsx、ppt、pptx 标头
这是我的代码,我尝试根据文档类型发送正确的标头。我找出了 pdf、doc 和 docx 的标题,但我仍然需要知道 Excel 和 Powerpoint 文件的正确标题。
任何帮助表示赞赏。
$document = urldecode($_GET['document']);
$extension = end(explode('.', $document));
$mimeType = '';
switch ($extension) {
case 'pdf':
$mimeType = 'pdf';
break;
case 'doc':
$mimeType = 'msword';
break;
case 'docx':
$mimeType = 'msword';
break;
case 'xls':
$mimeType = '';
break;
case 'xlsx':
$mimeType = '';
break;
case 'ppt':
$mimeType = '';
break;
case 'pptx':
$mimeType = '';
break;
}
header('Content-type: application/' . $mimeType);
Here is my code where I am trying to send a correct header depedning on a type of a document. I figured out the headers for pdf, doc and docx but I still need to know correct header for Excel and Powerpoint files.
Any help appreciated.
$document = urldecode($_GET['document']);
$extension = end(explode('.', $document));
$mimeType = '';
switch ($extension) {
case 'pdf':
$mimeType = 'pdf';
break;
case 'doc':
$mimeType = 'msword';
break;
case 'docx':
$mimeType = 'msword';
break;
case 'xls':
$mimeType = '';
break;
case 'xlsx':
$mimeType = '';
break;
case 'ppt':
$mimeType = '';
break;
case 'pptx':
$mimeType = '';
break;
}
header('Content-type: application/' . $mimeType);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.xls
application/vnd.ms-excel
.xlsx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.ppt
application/vnd.ms -powerpoint
.pptx
application/vnd.openxmlformats-officedocument.presentationml.presentation
您列出的其中一个是错误的:
.docx
application/vnd.openxmlformats-officedocument.wordprocessingml 。文档
.xls
application/vnd.ms-excel
.xlsx
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.ppt
application/vnd.ms-powerpoint
.pptx
application/vnd.openxmlformats-officedocument.presentationml.presentation
And one of those you have listed is wrong:
.docx
application/vnd.openxmlformats-officedocument.wordprocessingml.document
请参阅 http://www.w3schools.com/media/media_mimeref.asp 。
xls 为
application/vnd.ms-excel
,ppt 为application/vnd.ms-powerpoint
。See http://www.w3schools.com/media/media_mimeref.asp .
xls is
application/vnd.ms-excel
, ppt isapplication/vnd.ms-powerpoint
.由于大多数请求的类型都与 Microsoft Office 相关,因此此链接包含所有 Office MIME 类型(迄今为止我找到的最集中的来源):http://fileext.com/faq/office_mime_types.php
Since most of the types requested are Microsoft Office related, this link has all of the office mime types (the best focused source I've found so far): http://filext.com/faq/office_mime_types.php
您可以在上传文件后简单地 echo $_FILES['input_tag_name']['type'] 来了解该文件的 MIME 类型。
You can simply echo $_FILES['input_tag_name']['type'] after upload a file to know the MIME type of that file.