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

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

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

    2. <tfoot id='sHOro'></tfoot>
      <i id='sHOro'><tr id='sHOro'><dt id='sHOro'><q id='sHOro'><span id='sHOro'><b id='sHOro'><form id='sHOro'><ins id='sHOro'></ins><ul id='sHOro'></ul><sub id='sHOro'></sub></form><legend id='sHOro'></legend><bdo id='sHOro'><pre id='sHOro'><center id='sHOro'></center></pre></bdo></b><th id='sHOro'></th></span></q></dt></tr></i><div id='sHOro'><tfoot id='sHOro'></tfoot><dl id='sHOro'><fieldset id='sHOro'></fieldset></dl></div>
    3. PHP 强制下载导致 0 字节文件

      PHP Force Download Causing 0 Byte Files(PHP 强制下载导致 0 字节文件)

        <tfoot id='iaL3J'></tfoot>

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

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

              • 本文介绍了PHP 强制下载导致 0 字节文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 PHP 从我的 Web 服务器强制下载文件.我不是 PHP 专家,但我似乎无法解决以 0 字节大小下载文件的问题.

                I'm trying to force download files from my web server using PHP. I'm not a pro in PHP but I just can't seem to get around the problem of files downloading in 0 bytes in size.

                代码:

                $filename = "FILENAME...";
                
                header("Content-type: $type");
                header("Content-Disposition: attachment;filename=$filename");
                header("Content-Transfer-Encoding: binary");
                header('Pragma: no-cache');
                header('Expires: 0');
                set_time_limit(0);
                readfile($file);
                

                有人可以帮忙吗?谢谢.

                Can anybody help? Thanks.

                推荐答案

                您没有检查文件是否存在.尝试使用这个:

                You're not checking that the file exists. Try using this:

                $file = 'monkey.gif';
                
                if (file_exists($file))
                {
                    header('Content-Description: File Transfer');
                    header('Content-Type: application/octet-stream');
                    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));
                    ob_clean();
                    flush();
                    readfile($file);
                    exit;
                }else
                {
                    echo "File does not exists";
                }
                

                看看你得到了什么.

                您还应该注意,这会强制下载为八位字节流,即纯二进制文件.一些浏览器很难理解文件的确切类型.例如,如果您发送带有 Content-Type: application/octet-stream 标头的 GIF,则浏览器可能不会将其视为 GIF 图像.您应该添加特定检查以确定文件的内容类型,并发送适当的 Content-Type 标头.

                You should also note that this forces a download as an octet stream, a plain binary file. Some browsers will struggle to understand the exact type of the file. If, for example, you send a GIF with a header of Content-Type: application/octet-stream, then the browser may not treat it like a GIF image. You should add in specific checks to determine what the content type of the file is, and send an appropriate Content-Type header.

                这篇关于PHP 强制下载导致 0 字节文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 的问题)

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

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