首页 > 解决方案 > 如何下载大于 12 MB 的 PDF 文件?

问题描述

当下载大于 12 MB 的文件时,我在 php 中下载文件时遇到问题,但成功下载了小于 12 MB 的文件。这是我的代码:

 if(isset($_REQUEST["file"])){
    $file = urldecode($_REQUEST["file"]); // Decode URL-encoded string

        if(file_exists($file)) {
        $fp = fopen($file, "rb");

        header('Content-Description: File Transfer');

        header('Content-Type: application/octet-stream');

        header('Content-Disposition: attachment; filename="'.basename($file).'"');

        header('Content-Transfer-Encoding: binary');

        header('Connection: Keep-Alive');

        header('Expires: 0');

        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

        header("Cache-Control: public");
        header('Pragma: public');

        header('Content-Length: ' . filesize($file));

        set_time_limit(0);

        readfile($file);
        ob_end_clean();

        die(fpassthru($fp));
        fclose($fp);
        exit;
    }
}

问题已解决。只需删除文件名的符号字符。

标签: php

解决方案


推荐阅读