Closing Doman Auctions
DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
HomeRegisterMembershipsGetting StartedDomain Tools Domain EbooksSEO Software Domain Resellers Advertise

Go Back   DNForum - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars > Content Development > Website Development and Design Discussion > Coding/Programming/Languages
Register Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2009, 06:11 PM   #1 (permalink)
Platinum Lifetime Member
 
SGBoise's Avatar
 
Last Online: 09-28-2009 02:11 AM
iTrader: (1)
Join Date: Jan 2008
Posts: 38
DNF$: 60
Location: USA


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
SGBoise is offline   Reply With Quote
Sponsored Ads
Old 08-10-2009, 07:00 PM   #2 (permalink)
Luc
Old school
 
Luc's Avatar
 
Name: Luc L.
Last Online: Today 07:43 PM
iTrader: (7)
Join Date: Jul 2002
Posts: 1,551
DNF$: 13,027
Location: Los Angeles
Country:

Send a message via ICQ to Luc Send a message via AIM to Luc Send a message via MSN to Luc Send a message via Yahoo to Luc Send a message via Skype™ to Luc

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.
Luc is offline   Reply With Quote
Old 08-10-2009, 11:09 PM   #3 (permalink)
Platinum Lifetime Member
 
SGBoise's Avatar
 
Last Online: 09-28-2009 02:11 AM
iTrader: (1)
Join Date: Jan 2008
Posts: 38
DNF$: 60
Location: USA


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
SGBoise is offline   Reply With Quote
Old 08-10-2009, 11:11 PM   #4 (permalink)
Luc
Old school
 
Luc's Avatar
 
Name: Luc L.
Last Online: Today 07:43 PM
iTrader: (7)
Join Date: Jul 2002
Posts: 1,551
DNF$: 13,027
Location: Los Angeles
Country:

Send a message via ICQ to Luc Send a message via AIM to Luc Send a message via MSN to Luc Send a message via Yahoo to Luc Send a message via Skype™ to Luc

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.
Luc is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 09:16 PM.
Copyright @2001-2009 DNForum.com