- Joined
- Jan 29, 2008
- Messages
- 41
- Reaction score
- 0
Hello,
I'm using a script that allows my clients to download files from my store. The problem I'm running into is that for some reason the download stops at around 5 minutes. I'm guessing it's hitting the max_execute_limit set by the web host.
Below is the code that I'm currently using. Can anyone suggestion a different method to allow people to download large files?
What I think would be if I could redirect the user to the actual file once I validate that the person has access to the file but that would mean giving the person direct access to the folder which I don't want to do.
Thanks in advance.
I'm using a script that allows my clients to download files from my store. The problem I'm running into is that for some reason the download stops at around 5 minutes. I'm guessing it's hitting the max_execute_limit set by the web host.
Below is the code that I'm currently using. Can anyone suggestion a different method to allow people to download large files?
What I think would be if I could redirect the user to the actual file once I validate that the person has access to the file but that would mean giving the person direct access to the folder which I don't want to do.
PHP:
function readfile_chunked($file_name,$ret_bytes=true) {
set_time_limit(0);
$memory_limit = 1;
$chunksize = $memory_limit*(1024*1024);
$buffer = '';
$cnt =0;
$handle = fopen($file_name, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
exit;
if ($retbytes && $status) {
return $cnt;
}
return $status;
}