Serving large files with PHP

前端 未结 9 978
北海茫月
北海茫月 2020-12-13 07:51

So I am trying to serve large files via a PHP script, they are not in a web accessible directory, so this is the best way I can figure to provide access to them.

The

9条回答
  •  死守一世寂寞
    2020-12-13 08:19

    Strange, neither fpassthru() nor readfile() did it for me, always had a memory error. I resorted to use passthru() without the 'f':

    $name = 'mybigfile.zip';
    // send the right headers
    header("Content-Type: application/zip");
    header("Content-Length: " . filesize($name));
    // dump the file and stop the script
    passthru('/bin/cat '.$filename);
    exit;
    

    this execs 'cat' Unix command and send its output to the browser.

    comment for slim: the reason you just don't put a symlink to somewhere is webspace is SECURITY.

提交回复
热议问题