note 85950 deleted from function.fread by thiago
| From: | thiago@php.net | Date: | Mon, 27 Oct 2008 12:55:20 +0000 |
| Subject: | note 85950 deleted from function.fread by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145801@lists.php.net to get a copy of this message | ||
Note Submitter: hachimuto
----
HELLO CODERS.
I'm newbie to php and would like to show you a script that do:
*Download files from server.(implemanted)
*Support resume function.(implemanted)
*Determine the speed of download.(implemanted)
*Link protection(not yet and that's what I want to learn from you if you like.)
I explain the last feature:the server generates a link only "valid for this ip who requested it
.the link looks alike something : http://host/downloadit.o-n.php?idx=f7b1424c46ed6705879b2497c6453aaa
&file=yogui-cours-complet-php.zip
the server support resume,so multiple ranges requests,the same ip could download one more time with
this link.Now we need to prevent this from happening using something like this :
if($range["start"]!=$dbtikt["down_range"]){//IF4446
//IF THE CLIENT DIDN'T REQUESTED THE CORRECT RANGE.
exit();
//WE REFUSE THIS RANGE.
}//IF4446
now some tips ii learned:
=>to allow download of big files you must add code set_time_limit(0);
=>you must proccess the connection abort using ignore_user_abort(true),this means your script
will continue executing when the user disconnects from server.
so you could use if(connection_aborted()){do something} to perform finshing tasks.
=>don't put any thing before <?php code ?>,to avoid header already sent errors,or
simply turn on output buffer to prevent php from sending any output until you call flush functions.
=>to provide a limiting speed mechanism,i read always 32*speed bytes from file ,flush it and wait
a partical time using usleep(round((1000000*32)/1024)) and its working.