-1

I am trying to download a zip file via php but the downloading breaks in between abruptly and the code is as follows:

<?php
$zip_file="uploads/".$path; 
header('Content-type: application/zip');
header('Content-disposition: filename="'. $zip_file. '"');
header('Content-length:'. filesize($zip_file));
readfile($zip_file);
exit();
?>    

The file I am trying to download is in the range of 50-100MB and above in size.Please help me to get through Thanks in advance

2 Answers2

1

Here you go. I already use this code every time.

<?php
$zip_file = "uploads/".$path;
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($zip_file));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    readfile($zip_file);
    exit;
?>
Noman
  • 1,459
  • 2
  • 18
  • 38
0

I believe you're missing the keyword "attachment" in this line:

header('Content-disposition: filename="'. $zip_file. '"');

So it should be:

header('Content-disposition: attachment; filename="'. $zip_file. '"');
Jens Kooij
  • 379
  • 1
  • 8