如何预览和下载超过12 MB的PHP文件?

时间:2019-05-20 09:47:45

标签: php

单击预览链接并使用php脚本下载文件时出现问题,但是该文件少于12 MB可用。这是'#div' + 'even' 代码。

download.php

这是一条错误消息:

<?php
ignore_user_abort(true);
set_time_limit(0); // disable the time limit for this script
$filename='download/'.$_REQUEST['filename'];
if ($fd = fopen ($filename, "rb")) {
    $fsize = filesize($filename);
    $path_parts = pathinfo($filename);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
        header("Content-type: application/pdf");
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a file download
        break;
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
        break;
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fgets($fd, 2048);
        echo $buffer;
    }}
exit;
?>

仅供参考:第5行

Warning: fopen(download/22___006 TR - Copy - Copy - Copy (2).PDF): failed to open stream: No such file or directory in C:\xampp\htdocs\FMTmod2\download.php on line 5

1 个答案:

答案 0 :(得分:1)

您可以修改您的 php.ini 以下载/上传更大的文件,

Upload_max_filesize  - 1500 M
Max_input_time  - 1000
Memory_limit    - 640M
Max_execution_time -  1800
Post_max_size - 2000 M

或在 php 页中使用 init_set

对其进行修改
ini_set('memory_limit', '640M');