Serving file downloads through PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EoN
Forum Newbie
Posts: 22
Joined: Thu Oct 11, 2007 5:57 am

Serving file downloads through PHP

Post by EoN »

Hi all,

I'm getting a really weird problem, and I don't know a) where the problem actually lies. b) how to determine where the problem lies. c) how to fix it.

I have a website, that basically serves links to download files. Similar in architecture to 'yousendit.com' (but quite different really). Basically a file is created, and php links are given to various people to download the file which identifies the person.

The problem is, although MOST of the downloads for a file will work fine, occasionally every now & then downloads will just 'STOP' downloading in mid-download. It's intermittent, and if the user clicks download again, most often the whole thing will download. I have no idea what's causing it, but I'm desperate to solve it. My first thoughts are that it might be network problems on my shared web hosting environment. Is that possible? Here is the code I'm using to serve the file:

Code: Select all

header('HTTP/1.1 200 OK');
header('Date: ' . date("D M j G:i:s T Y"));
header('Last-Modified: ' . date("D M j G:i:s T Y"));
header("Content-Type: application/octet-stream");
header("Content-Length: " . (string)(filesize($fileHandle)) );
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename="'.$fileName.'"' );
readfile($fileHandle);
Can anyone think of why these downloads might just 'stop' all of a sudden? Is there any better way of serving files through PHP? Is it less reliable to serve files through php than directly through the file system?

Any help would be greatly appreciated as I've been stuck on this one for a whle!

Thanks,
EoN
User avatar
Sekka
Forum Commoner
Posts: 91
Joined: Mon Feb 18, 2008 10:25 am
Location: Huddersfield, West Yorkshire, UK

Re: Serving file downloads through PHP

Post by Sekka »

The files may be bigger than the allowed memory consumption in your php.ini?

This post may help you.

viewtopic.php?f=1&t=79656
Post Reply