PHP xls, xlsx, ppt, pptx headers

2022-08-30 18:38:41

这是我的代码,我试图在文档类型上发送正确的标头。我想出了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);

答案 1

.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.document


答案 2

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

xls 是 , ppt 是 。application/vnd.ms-excelapplication/vnd.ms-powerpoint


推荐