0

I have a small PHP scripts, which serves files. Just a simple download server.

I use the following code:

$mm_type="application/octet-stream";
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("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path); // outputs the content of the file
exit();

I stops download the file after 10-15 seconds. When I retry to download the file, it exactly stops at the same filesize. For example the file is 4GB, it stops downloading it at 230MB, when I restart the download, it again exactly stops at 230MB.

What is wrong with the script?

Sinan
  • 83
  • 3
  • 9
  • You don't need the string typecast for the file size. If you concatinate, PHP will do that for you. Have you checked what that file size is, by the way? Maybe it is wrong. This is especially probable for files larger than 2Gb when you have a 32 bit PHP. (Ints are also 32 bits then). – GolezTrol Sep 21 '14 at 08:34
  • GolezTrol, what do you I don't need typecast and concatinate? The server is running 64-bit OS + PHP. And have enough memory. I also check the filesize. – Sinan Sep 21 '14 at 08:44
  • `(string)(filesize($path))` can just be `(filesize($path))`. No need to typecast it to a string. – GolezTrol Sep 21 '14 at 08:45
  • Okay. Good that it isn't the platform. Maybe you can find a solution in [Readfile() and large files](http://stackoverflow.com/questions/11786734/readfile-and-large-files) - There also seem to be quite a lot of people who [bumped into certain limits](https://www.google.nl/webhp?#q=php+max+size+readfile) elsewhere on the internet. – GolezTrol Sep 21 '14 at 08:46

0 Answers0