【问题标题】:File with large size does not download with php大文件不能用 php 下载
【发布时间】:2013-10-23 20:26:15
【问题描述】:

我有以下文件下载脚本。

function download(){
        $this->file = $this->getFile();
        if($this->filesize <= 0 || $this->filesize == null){
            echo $this->filesize;
        } else {
           set_time_limit(0);

            header('Content-Description: File Transfer');
            header('Content-type:'.$this->contenttype);
            header('Content-Disposition: attachment; filename='.$this->filename.'.'.$this->extension);
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            ob_end_clean();
            readfile('/upload/'.$this->fileUid.'.'.$this->extension);
        }

        die();
    }

当我尝试下载小文件(以 Kbs 为单位)的文件时,文件下载成功,但如果文件大小很大,即大于 1MB,则文件无法正确下载,下载的文件大小以 Kbs 为单位,并且文件也打不开。任何人都可以在这方面帮助我,我尝试了ob_end_clean(),但没有奏效。请帮助我。 问候,

【问题讨论】:

  • 如果你在文本编辑器中打开下载的文件,最后一行是否有错误信息?
  • 是的,
    警告:readfile(/home/totalrec/upload/c924b6aa211faf2706e89abd3aaeea29.pdf) [function.readfile ]:无法打开流:在 /home/totalrec/public_html/test1/classes/file.class.php418 中没有这样的文件或目录
    是文件的内容。
  • 那我想问题就解决了,哈哈 :)
  • 但是文件在那里,我可以在上传文件夹中看到它
  • 你确定吗?您说该脚本适用于较小的文件,但不适用于大文件,没有其他变量。

标签: php download


【解决方案1】:

正如我在您的问题 cmets 中解决的那样,该文件在服务器上不存在。所以真正的问题是上传脚本。

您应该阅读Common Pitfalls Of File Upload 我的猜测是upload_max_filesize,尽管它可能是这些陷阱中的任何一个,具体取决于服务器设置。

【讨论】:

  • 这是否意味着上传脚本不适用于大文件?因为小文件工作正常。
  • 这是我的上传脚本 [ move_uploaded_file($this->tmp_name, "/home/totalrec/upload/" . $this->fileUid.'.'.$this->ext);]
  • @Shahzeb,您可以使用这个 PHP 下载脚本。适用于具有强大 MIME 支持的大型文件。 Large File Download我通过下载大约 2GB 的文件检查了这一点。它有效。
猜你喜欢
  • 2011-03-11
  • 1970-01-01
  • 2015-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-03
相关资源
最近更新 更多