• <legend id='FZb1m'><style id='FZb1m'><dir id='FZb1m'><q id='FZb1m'></q></dir></style></legend>

        <i id='FZb1m'><tr id='FZb1m'><dt id='FZb1m'><q id='FZb1m'><span id='FZb1m'><b id='FZb1m'><form id='FZb1m'><ins id='FZb1m'></ins><ul id='FZb1m'></ul><sub id='FZb1m'></sub></form><legend id='FZb1m'></legend><bdo id='FZb1m'><pre id='FZb1m'><center id='FZb1m'></center></pre></bdo></b><th id='FZb1m'></th></span></q></dt></tr></i><div id='FZb1m'><tfoot id='FZb1m'></tfoot><dl id='FZb1m'><fieldset id='FZb1m'></fieldset></dl></div>

        <tfoot id='FZb1m'></tfoot>

      1. <small id='FZb1m'></small><noframes id='FZb1m'>

          <bdo id='FZb1m'></bdo><ul id='FZb1m'></ul>

        通过 PHP 提供 .docx 文件

        时间:2023-07-16
          <tbody id='nNrQq'></tbody>
        1. <small id='nNrQq'></small><noframes id='nNrQq'>

            <i id='nNrQq'><tr id='nNrQq'><dt id='nNrQq'><q id='nNrQq'><span id='nNrQq'><b id='nNrQq'><form id='nNrQq'><ins id='nNrQq'></ins><ul id='nNrQq'></ul><sub id='nNrQq'></sub></form><legend id='nNrQq'></legend><bdo id='nNrQq'><pre id='nNrQq'><center id='nNrQq'></center></pre></bdo></b><th id='nNrQq'></th></span></q></dt></tr></i><div id='nNrQq'><tfoot id='nNrQq'></tfoot><dl id='nNrQq'><fieldset id='nNrQq'></fieldset></dl></div>
            <legend id='nNrQq'><style id='nNrQq'><dir id='nNrQq'><q id='nNrQq'></q></dir></style></legend>
          • <tfoot id='nNrQq'></tfoot>
            • <bdo id='nNrQq'></bdo><ul id='nNrQq'></ul>

                  本文介绍了通过 PHP 提供 .docx 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在尝试使用 Php 提供 .docx 文件时遇到问题.上传文件时,我会检测文件 MIME 类型,并根据 MIME 类型使用具有正确扩展名的文件上传文件;例如下面:

                  I'm having issues when attempting to serve a .docx file using Php. When uploading the file I detect the file mime type and upload the file using the file with the correct extension based on the mime type; e.g. below:

                  application/msword - doc
                  application/vnd.openxmlformats-officedocument.wordprocessingml.document - docx
                  

                  当尝试提供文件以供下载时,我会根据 mime 类型检测扩展名和提供服务,例如

                  When attempting to serve the files for download, I do the reverse in detecting the extension and serving based on the mime type e.g.

                  public static function fileMimeType($extention) {
                  
                          if(!is_null($extention)) {
                              switch($extention) {
                                  case 'txt':
                                      return 'text/plain';
                                      break;
                                  case 'odt':
                                      return 'application/vnd.oasis.opendocument.text';
                                      break;
                                  case 'doc':
                                      return 'application/msword';
                                      break;
                                  case 'docx':
                                      return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
                                      break;
                                  case 'jpg':
                                      return 'image/jpeg';
                                      break;
                                  case 'png':
                                      return 'image/png';
                                      break;
                                  case 'pdf':
                                      return 'application/pdf';
                                      break;
                                  default:
                                      break;
                              }
                          }
                  
                  }
                  

                  所有文件似乎都可以正确下载并且可以正常打开,但是在尝试打开 docx 文件时,Word(在多个文件上)会引发错误,指出文件已损坏.

                  All files appear to download correctly and open fine but when attempting to open a docx file, Word (on multiple files) throws a error stating the file is corrupt.

                  任何想法都会很棒,谢谢.

                  Any ideas would be great, thanks.

                  编辑 #1

                  try {
                  
                   $file = new Booking_Document((int)$get_data['bookingDocument']);
                   header('Content-Type: ' . Booking_Document::fileMimeType($file->getDocumentType()));
                   header('Content-Disposition: attachment; filename=' . $file);
                   header('Expires: 0');
                   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                   header('Pragma: public');
                   echo readfile(Zend_Registry::get(static::$_uploadDir).$this->_id);
                  } catch (Exception $e) {
                   View_Helpers_FlashMessages::addMessage(array('message' => $e->getMessage(), 'type' => 'error'));
                  }
                  exit;
                  

                  已修复

                  在调用 readfile() 之前,我添加了 ob_clean() 和 flush(),这似乎解决了问题.

                  Prior to calling readfile() I added ob_clean() and flush() which appears to have fixed the problem.

                  推荐答案

                  已修复;在调用 readfile() 之前,我添加了 ob_clean() 和 flush() 这似乎已经解决了这个问题.

                  Fixed; prior to calling readfile() I added ob_clean() and flush() which appears to have fixed the problem.

                  这篇关于通过 PHP 提供 .docx 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何从 php 中的 .doc 模板创建一个 word .doc 文件 下一篇:使用 PHP 从 MS Word 文档中提取图像的最简单方法?

                  相关文章

                      <legend id='dOJ0c'><style id='dOJ0c'><dir id='dOJ0c'><q id='dOJ0c'></q></dir></style></legend>
                      • <bdo id='dOJ0c'></bdo><ul id='dOJ0c'></ul>

                      <small id='dOJ0c'></small><noframes id='dOJ0c'>

                    1. <i id='dOJ0c'><tr id='dOJ0c'><dt id='dOJ0c'><q id='dOJ0c'><span id='dOJ0c'><b id='dOJ0c'><form id='dOJ0c'><ins id='dOJ0c'></ins><ul id='dOJ0c'></ul><sub id='dOJ0c'></sub></form><legend id='dOJ0c'></legend><bdo id='dOJ0c'><pre id='dOJ0c'><center id='dOJ0c'></center></pre></bdo></b><th id='dOJ0c'></th></span></q></dt></tr></i><div id='dOJ0c'><tfoot id='dOJ0c'></tfoot><dl id='dOJ0c'><fieldset id='dOJ0c'></fieldset></dl></div>
                    2. <tfoot id='dOJ0c'></tfoot>