Welcome to Welcome to DNF.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars

If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the largest domain name community on the internet and continues to grow every day. There are over 105,000 domainers on DNForum doing everything from buying domains, selling domains, learning about domains and discussing domains. Take a minute and Register.

Register Today on DNForum IT'S FREE!

Results 1 to 4 of 4
  1. #1
    Platinum Lifetime Member
    SGBoise's Avatar
    Join Date
    Jan 2008
    Location
    USA
    Posts
    41
    DNF$
    275
    Bank
    0
    Total DNF$
    275
    Donate  

    Question Large file download script

    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 Code:
    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;

    Thanks in advance.
    Video Script - The ultimate media site script
    AutoVideoScript com - Run your own youtube sharing site

  2. #2
    Old school
    Luc's Avatar
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    1,618
    DNF$
    13,511
    Bank
    0
    Total DNF$
    13,511
    Donate  
    There are a few ways of handling this...

    1. Simply increase the max execution time of your PHP scripts in PHP.ini so that it can run for more than 5 minutes.

    2. Create a temporary directory that's web accessible. Then LINK (ln -s) the file the user is trying to download, to a temporary file with a random filename (ex: ln -s SOURCEFILE /www/site/tmp/RANDOMFILE.zip) and using PHP use header("Location: URLTOTMPFILE). That will basically send a redirect header to the remote host, and then apache will handle the actual download.

    Since you're using file linking in option #2, the file doesn't use up any space on your PC but also doesn't reveal the true path and filename of the actual file, but rather some temporary file (which you can delete from cron every XX days).

    Good luck,
    Luc L.
    Looking for type-in domains? Page Rank Domains? Link Popularity Domains? Alexa Domains?
    Domain Research Tool Finds, Tracks and Acquires domains.

  3. #3
    Platinum Lifetime Member
    SGBoise's Avatar
    Join Date
    Jan 2008
    Location
    USA
    Posts
    41
    DNF$
    275
    Bank
    0
    Total DNF$
    275
    Donate  
    Luc, you're a genius. I tried 1 already but 2 is a great idea. I'll have to try that.

    Thanks.

    Quote Originally Posted by Luc View Post
    There are a few ways of handling this...

    1. Simply increase the max execution time of your PHP scripts in PHP.ini so that it can run for more than 5 minutes.

    2. Create a temporary directory that's web accessible. Then LINK (ln -s) the file the user is trying to download, to a temporary file with a random filename (ex: ln -s SOURCEFILE /www/site/tmp/RANDOMFILE.zip) and using PHP use header("Location: URLTOTMPFILE). That will basically send a redirect header to the remote host, and then apache will handle the actual download.

    Since you're using file linking in option #2, the file doesn't use up any space on your PC but also doesn't reveal the true path and filename of the actual file, but rather some temporary file (which you can delete from cron every XX days).

    Good luck,
    Luc L.
    Video Script - The ultimate media site script
    AutoVideoScript com - Run your own youtube sharing site

  4. #4
    Old school
    Luc's Avatar
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    1,618
    DNF$
    13,511
    Bank
    0
    Total DNF$
    13,511
    Donate  
    No problemo bro. If you need sample code or something shoot me a PM. I use that second method all the time.

    Just make sure you read up on the LN command (file linking) so you know how it works, but it should be fairly simple.

    Good luck!
    Luc
    Looking for type-in domains? Page Rank Domains? Link Popularity Domains? Alexa Domains?
    Domain Research Tool Finds, Tracks and Acquires domains.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Domain name forum recommended by Domaining.com