<small id='8gPhI'></small><noframes id='8gPhI'>

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

        <tfoot id='8gPhI'></tfoot>
      1. <legend id='8gPhI'><style id='8gPhI'><dir id='8gPhI'><q id='8gPhI'></q></dir></style></legend>

        • <bdo id='8gPhI'></bdo><ul id='8gPhI'></ul>

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

        Download of .zip file runs a corrupted file php(.zip 文件的下载运行损坏的文件 php)
          <bdo id='8PcKT'></bdo><ul id='8PcKT'></ul>

                <tbody id='8PcKT'></tbody>
            • <tfoot id='8PcKT'></tfoot>

                  <legend id='8PcKT'><style id='8PcKT'><dir id='8PcKT'><q id='8PcKT'></q></dir></style></legend>

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

                  本文介绍了.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

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

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

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

                              <tbody id='lN1eA'></tbody>