<tfoot id='Vo7ez'></tfoot>
  • <small id='Vo7ez'></small><noframes id='Vo7ez'>

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

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

      1. 使用 PHP 下载脚本发送正确的文件大小

        时间:2023-09-25
          • <bdo id='rRnHx'></bdo><ul id='rRnHx'></ul>
              <tbody id='rRnHx'></tbody>

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

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

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

              • <tfoot id='rRnHx'></tfoot>
                1. 本文介绍了使用 PHP 下载脚本发送正确的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我用 PHP 创建了一个文件下载脚本,它可以工作,但网络浏览器将文件报告为未知长度".我的代码如下:

                  I created a file download script in PHP, it works, but web browsers report the file as "Unknown Length". My code is as follows:

                  function downloadFile($file){
                    // Set up the download system...
                    header('Content-Description: File Transfer');
                    header('Content-Type: '.mime_content_type($file));
                    header('Content-Disposition: attachment; filename="'.basename($file).'"');
                    header('Content-Transfer-Encoding: binary');
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header('Pragma: public');
                    header('Content-Length: '.filesize($file));
                  
                    // Flush the cache
                    ob_clean();
                    flush();
                  
                    // Send file to browser
                    readfile($file);
                  
                    // DO NOT DO ANYTHING AFTER FILE DOWNLOAD
                    exit;
                  }
                  

                  推荐答案

                  原文来自 http://paul.luminos.nl/update/471:

                  CrimsonBase 网站通过一个强大的 PHP 脚本来验证下载,类似于 Andrew Johnson 发布的脚本在 他关于 PHP 控制的文件下载的文章中.

                  The CrimsonBase website verifies downloads by passing them through a robust PHP script similar to the one published by Andrew Johnson in his article about PHP-controlled file downloads.

                  Andrew 在文章末尾发表了一个非常重要的评论:

                  Andrew makes a very important comment at the end of the article:

                  "如果您使用 Zlib、mod_deflate 等压缩文件,则 Content-Length 标头将不准确,因此您最终会看到未知大小"和剩余时间未知"下载文件时."

                  "If you compress files with Zlib, mod_deflate and so on the Content-Length header won't be accurate so you'll end up seeing "Unknown size" and "Unknown time remaining" when downloading files."

                  我想强调一点:如果您的浏览器似乎没有遵守由您的 PHP 脚本生成的标头——尤其是 Content-Length——很可能是 Apache 的 mod_deflate 扩展已启用.

                  I would like to stress this: if your browser doesn't appear to be obeying the headers generated by your PHP script—especially Content-Length—it is fairly likely that Apache's mod_deflate extension is enabled.

                  您可以使用适用的 .htaccess 文件中的以下行轻松为单个脚本禁用它:

                  You can easily disable it for a single script using the following line in an applicable .htaccess file:

                  SetEnvIfNoCase Request_URI ^/download.php no-gzip dont-vary
                  

                  此处假定 download.php 位于服务器根目录路径中的下载脚本中(例如 www.crimsonbase.com/download.php).(那是因为正则表达式是^/download.php.)

                  where download.php is here assumed to be in the download script located in the server's root directory path (e.g. www.crimsonbase.com/download.php). (That's because the regular expression is ^/download.php.)

                  这篇关于使用 PHP 下载脚本发送正确的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何获取确切的浏览器名称和版本? 下一篇:浏览器显示 而不是 ´

                  相关文章

                  最新文章

                  • <bdo id='YUHnb'></bdo><ul id='YUHnb'></ul>

                  1. <legend id='YUHnb'><style id='YUHnb'><dir id='YUHnb'><q id='YUHnb'></q></dir></style></legend>

                    1. <tfoot id='YUHnb'></tfoot>

                    2. <small id='YUHnb'></small><noframes id='YUHnb'>

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