PHP readfile() and large files

后端 未结 7 838
逝去的感伤
逝去的感伤 2020-12-05 20:12

When using readfile() -- using PHP on Apache -- is the file immediately read into Apache\'s output buffer and the PHP script execution completed, or does the PHP script exec

7条回答
  •  暖寄归人
    2020-12-05 20:35

    Try using stream_copy_to_stream() instead. I find is has fewer problems than readfile().

    set_time_limit(0);
    $stdout = fopen('php://output', 'w');
    $bfname = basename($fname);
    
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"$bfname\"");
    
    $filein = fopen($fname, 'r');
    stream_copy_to_stream($filein, $stdout);
    
    fclose($filein);
    fclose($stdout);
    

提交回复
热议问题