Problem trying to download large files

2

I am using this code to download with php, small files works, now as big as 1Gb end up coming corrupted.

$arquivo = $_GET['nome']; //nome do Arquivo
$local = $_GET['dir']; //pasta onde está o arquivo

header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($local.$arquivo));
header('Content-Disposition: filename='.$arquivo);
header("Content-Disposition: attachment; filename=".basename($local.$arquivo));

//envia o download
readfile($local.$arquivo);

<a href="download?nome=arquivo.ext&dir=pasta/">Download</a>
    
asked by anonymous 07.08.2018 / 02:47

1 answer

2

One option is to use x-sendfile . First of all you need to have mod_xsendfile in the server module. If you do not have it, the link above has a download area.

Then you need to configure it in your httpd.conf file by adding this:

XSendFile on // <-- ligou a criança
XSendFilePath /path/to/files/directory // <-- diretório dos arquivos que estão liberados para serem acessados

And then you'll be able to use it:

header("X-Sendfile: $arquivo"); // <--- aqui está!
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=".basename($local.$arquivo));

I used it only once and it worked with a very large file!

Here's a GitHub example

    
07.08.2018 / 04:25