• 0

Bandwidth Limiting..


Question

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

  • 0

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

  • 0

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

  • 0

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

  • 0

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

  • 0

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

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.