<legend id='V35GW'><style id='V35GW'><dir id='V35GW'><q id='V35GW'></q></dir></style></legend>

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

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

      1. 下载 .zip 文件运行损坏的文件 php

        Download of .zip file runs a corrupted file php(下载 .zip 文件运行损坏的文件 php)
          <i id='Mfk34'><tr id='Mfk34'><dt id='Mfk34'><q id='Mfk34'><span id='Mfk34'><b id='Mfk34'><form id='Mfk34'><ins id='Mfk34'></ins><ul id='Mfk34'></ul><sub id='Mfk34'></sub></form><legend id='Mfk34'></legend><bdo id='Mfk34'><pre id='Mfk34'><center id='Mfk34'></center></pre></bdo></b><th id='Mfk34'></th></span></q></dt></tr></i><div id='Mfk34'><tfoot id='Mfk34'></tfoot><dl id='Mfk34'><fieldset id='Mfk34'></fieldset></dl></div>

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

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

                <tfoot id='Mfk34'></tfoot>

                  本文介绍了下载 .zip 文件运行损坏的文件 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试强制下载受保护的 zip 文件(我不希望人们在未先登录的情况下访问它.

                  I'm trying to force a download of a protected zip file (I don't want people to access it without logging in first.

                  我为 login 等创建了函数,但我遇到了下载文件损坏的问题.

                  I have the function created for the login and such , but I'm running into a problem where the downloaded file is corrupting.

                  这是我的代码:

                  $file='../downloads/'.$filename;
                  header("Content-type: application/zip;
                  ");
                  header("Content-Transfer-Encoding: Binary");
                  header("Content-length: ".filesize($file).";
                  ");
                  header("Content-disposition: attachment; filename="".basename($file).""");
                  readfile("$file");
                  exit();
                  

                  这是错误:无法打开文件:它似乎不是有效的存档.

                  否则文件下载正常,所以一定是我的标题有问题.

                  The file downloads fine otherwise, so it must be something I'm doing wrong with the headers.

                  有什么想法吗?

                  推荐答案

                  此问题可能有多种原因.也许您的文件未找到或无法读取,因此文件的内容只是 PHP 错误消息.或者 HTTP 标头已经发送.或者您有一些额外的输出会破坏您的文件内容.

                  This issue can have several causes. Maybe your file is not found or it can not be read and thus the file’s content is just the PHP error message. Or the HTTP header is already sent. Or you have some additional output that then corrupts your file’s content.

                  尝试在脚本中添加一些错误处理,如下所示:

                  Try to add some error handling into your script like this:

                  $file='../downloads/'.$filename;
                  if (headers_sent()) {
                      echo 'HTTP header already sent';
                  } else {
                      if (!is_file($file)) {
                          header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
                          echo 'File not found';
                      } else if (!is_readable($file)) {
                          header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
                          echo 'File not readable';
                      } else {
                          header($_SERVER['SERVER_PROTOCOL'].' 200 OK');
                          header("Content-Type: application/zip");
                          header("Content-Transfer-Encoding: Binary");
                          header("Content-Length: ".filesize($file));
                          header("Content-Disposition: attachment; filename="".basename($file).""");
                          readfile($file);
                          exit;
                      }
                  }
                  

                  这篇关于下载 .zip 文件运行损坏的文件 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                • <legend id='DibHc'><style id='DibHc'><dir id='DibHc'><q id='DibHc'></q></dir></style></legend>

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

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

                          <bdo id='DibHc'></bdo><ul id='DibHc'></ul>
                            <tbody id='DibHc'></tbody>