chmsant Posted February 3, 2006 Share Posted February 3, 2006 Alright, as many know I help to host files for Autopatcher, and my bandwidth gets sucked up very quickly. Is there any way to throttle the bandwidth or limit the number of downloads each day/week/hour with some sort of script? Link to comment Share on other sites More sharing options...
0 Kussie Posted February 3, 2006 Share Posted February 3, 2006 Well what you could do is send each download through a ssript (ie have user go to apage to download it and what not), and then increment the download count in a file our database everytime it is downloaded. If it reaches a certian level then instead of starting the download it says something about it not being aviable at this time and too try agian later. Link to comment Share on other sites More sharing options...
0 smooths* Posted February 3, 2006 Share Posted February 3, 2006 Any examples of such a script? i'd like this too (Y) Link to comment Share on other sites More sharing options...
0 Kussie Posted February 3, 2006 Share Posted February 3, 2006 Not off the top of my head. But go to hotscripts and look for a download manager Link to comment Share on other sites More sharing options...
0 chmsant Posted February 3, 2006 Author Share Posted February 3, 2006 alright i'll take a look. Any more suggestions/code bits? Link to comment Share on other sites More sharing options...
0 Kudos Veteran Posted February 3, 2006 Veteran Share Posted February 3, 2006 Make sure you host it one directory beneath your web directory, so people can't discover the direct link and bypass your restrictions. You can then just use a script to fire it at the user. /k Link to comment Share on other sites More sharing options...
0 TurboTuna Posted February 3, 2006 Share Posted February 3, 2006 heres something i used to use, just modify it to use a db and $i++ to limit the count <?php $filename = $_GET['file']; // required for IE, otherwise Content-disposition is ignored if(ini_get('zlib.output_compression')) ini_set('zlib.output_compression', 'Off'); // addition by Jorg Weske $file_extension = strtolower(substr(strrchr($filename,"."),1)); if( $filename == "" ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>"; exit; } elseif ( ! file_exists( $filename ) ) { echo "<html><title>eLouai's Download Script</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>"; exit; }; switch( $file_extension ) { case "pdf": $ctype="application/pdf"; break; case "exe": $ctype="application/octet-stream"; break; case "zip": $ctype="application/zip"; break; case "doc": $ctype="application/msword"; break; case "xls": $ctype="application/vnd.ms-excel"; break; case "ppt": $ctype="application/vnd.ms-powerpoint"; break; case "gif": $ctype="image/gif"; break; case "png": $ctype="image/png"; break; case "jpeg": case "jpg": $ctype="image/jpg"; break; default: $ctype="application/force-download"; } header("Pragma: public"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); // change, added quotes to allow spaces in filenames, by Rajkumar Singh header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($filename)); readfile("$filename"); exit(); ?> Link to comment Share on other sites More sharing options...
0 chmsant Posted February 4, 2006 Author Share Posted February 4, 2006 Since I am a PHP noob, where would DB info go? Link to comment Share on other sites More sharing options...
0 Ianmac45 Posted February 4, 2006 Share Posted February 4, 2006 i just gotta ask this, but near the end, what's the difference between readfile("$filename"); and readfile($filename); ? or is there no difference? :p Link to comment Share on other sites More sharing options...
0 Kudos Veteran Posted February 4, 2006 Veteran Share Posted February 4, 2006 The quotes are not needed when dealing with a variable on its own, although you could use it to insert a variable into a string; readfile($filename) is all you need. /k Link to comment Share on other sites More sharing options...
0 john smith 1924 Veteran Posted February 4, 2006 Veteran Share Posted February 4, 2006 The code posted above sends the file to the user. So what i'd do is something like this. 1. user clicks link 2. goes through page 1 - this counts the number of downloads for the file 3. page 1 notes the download in the database; if number is greater than x then it doesn't send people to the next step (if you want to limit bandwidth - you'd do this as a check - x * filesize < bandwidth limit = allow people through, x * filesize >= bandwidth don't) 4. send the file to the end user. Now this doesn't really help answer your question ( sorry! ) but hopefully helps you conceptualize it a bit better. Link to comment Share on other sites More sharing options...
0 fock neow1n Posted February 5, 2006 Share Posted February 5, 2006 Well if it's apache on *nix you could download bandwidth mods for it. There are plenty of em for *nix, but none for Apache on Windows. Link to comment Share on other sites More sharing options...
0 chmsant Posted February 6, 2006 Author Share Posted February 6, 2006 Here's a good script for you all that I happend to stumble across... http://sourceforge.net/projects/dsplus Link to comment Share on other sites More sharing options...
Question
chmsant
Alright, as many know I help to host files for Autopatcher, and my bandwidth gets sucked up very quickly. Is there any way to throttle the bandwidth or limit the number of downloads each day/week/hour with some sort of script?
Link to comment
Share on other sites
12 answers to this question
Recommended Posts