NameSilo

Large file download script

Spaceship Spaceship
Watch

SGBoise

Established Member
Impact
1
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.

PHP:
function readfile_chunked($file_name,$ret_bytes=true) {
    // important for large files
    set_time_limit(0);
    // determine memory limit
    //$memory_limit = (int)get_cfg_var('memory_limit');
    //if($memory_limit==0) $memory_limit = 1;
    $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;
}

Thanks in advance.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
You got a set_time_limit(0); in the header?
 
0
•••
Yes, I tried that. I think my web host has a had limit set so the script stops once that hits. I'm looking into using link() to create a link to the actual. I'm hoping that will work.
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back