0

I have used following code to download approximate 920MB file,

set_time_limit(0);

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");

header("X-Sendfile: $zipname");                 // For Large Files

header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"".$zipname."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($directory_location . '/' . $zipname));
ob_end_flush();

readfile($directory_location . '/' . $zipname);

Before this code i did some study with the following links Using X-Sendfile with Apache/PHP, Streaming a large file using PHP and Limit download speed using PHP but not much helpful to me because file download still takes more time with just (2MB) file. It's not showing and transfer rate or anything else. I want download start to serve file with around 60Kbps, with all files (Large or small)

UPDATE: One more thing i noticed its not showing any download process just executing and after sometime display the pop-up to choose the location, and after hitting save button its direct save to the computer without any downloading process window :(

Please help me to guide the right way.

Community
  • 1
  • 1
jogesh_pi
  • 9,762
  • 4
  • 37
  • 65
  • If you researched those, why haven't you used any of the code? – N.B. Oct 21 '13 at 09:39
  • @N.B. i tried all, but mention in question only one. I tried one by one but all are not working for me :( – jogesh_pi Oct 21 '13 at 09:44
  • Did you actually install mod_xsednfile? It needs to be added into apache. It was going to be my first suggestion. Second question: why do it through PHP at all? Why not do it directly? – Robbie Oct 21 '13 at 10:12
  • @Robbie, I didn't had any idea about mod_xsendfile apache module, i will try to enable it, second - I have to track some extra stuff that's why i used php to download like track the IP, send email to receiver, admin etc. – jogesh_pi Oct 21 '13 at 10:14
  • In that case, that's my answer - read this: https://tn123.org/mod_xsendfile/ – Robbie Oct 21 '13 at 10:25
  • @Robbie thanks for your kind help, i will try the given link. Just want to know, is this the best solution to download large file? – jogesh_pi Oct 21 '13 at 10:27
  • Short of a direct download, serving off a CDN (content delivery network) or Amazon's servers, etc, yes (AFAIK). – Robbie Oct 21 '13 at 10:33

1 Answers1

0

Based on above comments there are two solutions:

1) Just download the file directly. You don't appear to be doing any validation, so if not, then just pass the user to the file to download and let apache handle it.

2) If you do need validation / pre-processing, then check mod_xsendfile - adding the header isn't enough, you actually need to add the mod to apache. If you're in Linux then compile from source (https://tn123.org/mod_xsendfile/). If you're not in Linux then mod_xsendfile for Win x64? has a response from the author saying he can provide binaries - but that's in 2010. There's a bit of advice around the web - although it's been a while since I looked at it so can't really help much more.

Community
  • 1
  • 1
Robbie
  • 17,605
  • 4
  • 35
  • 72