PHP xls、xlsx、ppt、pptx 标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3318288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:20:01  来源:igfitidea点击:

PHP xls, xlsx, ppt, pptx headers

phpms-office

提问by Richard Knop

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.

这是我的代码,我试图根据文档类型发送正确的标题。我找出了 pdf、doc 和 docx 的标题,但我仍然需要知道 Excel 和 Powerpoint 文件的正确标题。

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);

回答by Mark Baker

.xls

.xls

application/vnd.ms-excel

应用程序/vnd.ms-excel

.xlsx

.xlsx

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

应用程序/vnd.openxmlformats-officedocument.spreadsheetml.sheet

.ppt

.ppt

application/vnd.ms-powerpoint

应用程序/vnd.ms-powerpoint

.pptx

.pptx

application/vnd.openxmlformats-officedocument.presentationml.presentation

应用程序/vnd.openxmlformats-officedocument.presentationml.presentation

And one of those you have listed is wrong:

您列出的其中一项是错误的:

.docx

.docx

application/vnd.openxmlformats-officedocument.wordprocessingml.document

应用程序/vnd.openxmlformats-officedocument.wordprocessingml.document

回答by Maerlyn

See http://www.w3schools.com/media/media_mimeref.asp.

请参阅http://www.w3schools.com/media/media_mimeref.asp

xls is application/vnd.ms-excel, ppt is application/vnd.ms-powerpoint.

xls 是application/vnd.ms-excel,ppt 是application/vnd.ms-powerpoint

回答by Code Jockey

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

由于请求的大多数类型与 Microsoft Office 相关,因此此链接包含所有办公室 mime 类型(迄今为止我找到的最集中的来源):http: //fileext.com/faq/office_mime_types.php

回答by Biswadeep Sarkar

You can simply echo $_FILES['input_tag_name']['type'] after upload a file to know the MIME type of that file.

您可以在上传文件后简单地 echo $_FILES['input_tag_name']['type'] 以了解该文件的 MIME 类型。