• <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 文件

        Serving .docx files through Php(通过 PHP 提供 .docx 文件)
          <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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

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

                          <tbody id='dOJ0c'></tbody>

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

                          • <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>
                          • <tfoot id='dOJ0c'></tfoot>