Page 1 of 2

Limiting download speed

PostPosted: Wed Aug 24, 2011 10:34 am
by theunreal
Hello.
I want to make a Guest download and limit it to 500KB/S and VIP download with unlimited download.
How I can do such a thing and limit the download speed with DFH? I guess the rest I'll be able to to myself, I just have no idea how to limit the download speed.

Re: Limiting download speed

PostPosted: Wed Aug 24, 2011 12:26 pm
by pmanth
I agree - Speed limiting would be good, so it doesn't drain all of my connection speed on my host :)

Re: Limiting download speed

PostPosted: Fri Aug 26, 2011 12:37 pm
by theunreal
Hmm, Any help with this?

Re: Limiting download speed

PostPosted: Fri Aug 26, 2011 6:04 pm
by SamEA
As soon as I'm near a PC, I'll example how to limit download speeds.

Re: Limiting download speed

PostPosted: Sun Aug 28, 2011 2:07 pm
by theunreal
SamEA wrote:As soon as I'm near a PC, I'll example how to limit download speeds.


Waiting for this

Re: Limiting download speed

PostPosted: Mon Aug 29, 2011 9:26 pm
by theunreal
Still need help.

Re: Limiting download speed

PostPosted: Wed Aug 31, 2011 4:39 pm
by theunreal
No one can help I guess..

Re: Limiting download speed

PostPosted: Thu Sep 01, 2011 7:24 pm
by SamEA
I'm currently abroad at the moment and finding Internet access is limited. Patience is needed at such times. If however it's urgent, you may search on Google how to limit PHP download speeds and implement it in ./download2.php

Re: Limiting download speed

PostPosted: Mon Sep 05, 2011 11:14 pm
by SamEA
Repalce ./download2.php with the following code:
Code: Select all
<?php
///////////////////////////////////////////////////////////////////////////
//  Product: Daddy's File Host               
//  Version: 1.2                       
//                       
// by DaddyScripts.com                 
//                               
// original source code by Jim (j-fx.ws) and Steven (galaxyscripts.com)
//////////////////////////////////////////////////////////////////////////

require_once("./config.php");

if(in_array($language, $LANGUAGE_LIST)) {
  include('./lang/'.$language.'.php');
} else {
  include('./lang/'.$LANGUAGE_LIST[0].'.php');
}

$bans=file("./secure/bans.dfh");
foreach($bans as $line)
{
  if ($line==$_SERVER['REMOTE_ADDR']){
?> <center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top> <?
    echo "$lang[younallow]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
    include("./footer.php");
    die();
  }
}

if(!isset($_GET['a']) || !isset($_GET['b']))
{
  echo "<script>window.location = '".$scripturl."';</script>";
}

$validdownload = 0;


$filecrc = $_GET['a'];
$filecrctxt = $filecrc.".dfh";
if (file_exists("./files/".$filecrctxt)) {
   $fh = fopen ("./files/".$filecrctxt,r);
   $thisline= explode('|', fgets($fh));
   if ($thisline[0]==$_GET['a'] && md5($thisline[2].$_SERVER['REMOTE_ADDR'])==$_GET['b'])
      $validdownload=$thisline;
   fclose($fh);
}
if($validdownload==0) {
?> <center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top>
<?
    echo "<center>$lang[inlink]</center>";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
    include("./footer.php");
    die();
}

$userip = $_SERVER['REMOTE_ADDR'];
$time = time();

$filesize = filesize("./storage/".$validdownload[0]);
$filesize = $filesize / 1048576;

if($filesize > $nolimitsize)
{
$newfile = "./downloader/".$userip.".dfh";
$f=fopen($newfile, "w");
fwrite ($f,$userip."|".$time."|");
fclose($f);
chmod($newfile,0777);
}


$validdownload[4] = time();

session_start();
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']==md5(md5($adminpass))) {
}
else {

// begin separate file mod
$newfile = "./files/$filecrc" . ".dfh";
$f=fopen($newfile, "w");
fwrite ($f,$validdownload[0]."|". $validdownload[1]."|". $validdownload[2]."|". $validdownload[3]."|". $validdownload[4]."|".($validdownload[5]+1)."|".$validdownload[6]."|".$validdownload[7]."|".$validdownload[8]."|\n");
fclose($f);
// end separate file mod
}

$speed_rate = 100;
//Speed is in KB/s (Kilobytes per second).

header('Cache-control: private');
header('Content-type: application/octetstream');
header('Content-Length: ' . filesize("./storage/".$validdownload[0]));
header('Content-Disposition: filename='.$validdownload[1]);

flush();

$dfile = fopen("./storage/".$validdownload[0], "r");

while (!feof($dfile)){
print fread($dfile, round($speed_rate * 1024));
flush();
sleep(1);
}

fclose($dfile);

?>


To adjust the speed rate of the download, modify the speed_rate variable.

Note: The above script might cause DFH to use more resources than normal.

Re: Limiting download speed

PostPosted: Fri Sep 09, 2011 4:51 pm
by theunreal
SamEA wrote:Repalce ./download2.php with the following code:
Code: Select all
<?php
///////////////////////////////////////////////////////////////////////////
//  Product: Daddy's File Host               
//  Version: 1.2                       
//                       
// by DaddyScripts.com                 
//                               
// original source code by Jim (j-fx.ws) and Steven (galaxyscripts.com)
//////////////////////////////////////////////////////////////////////////

require_once("./config.php");

if(in_array($language, $LANGUAGE_LIST)) {
  include('./lang/'.$language.'.php');
} else {
  include('./lang/'.$LANGUAGE_LIST[0].'.php');
}

$bans=file("./secure/bans.dfh");
foreach($bans as $line)
{
  if ($line==$_SERVER['REMOTE_ADDR']){
?> <center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top> <?
    echo "$lang[younallow]";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
    include("./footer.php");
    die();
  }
}

if(!isset($_GET['a']) || !isset($_GET['b']))
{
  echo "<script>window.location = '".$scripturl."';</script>";
}

$validdownload = 0;


$filecrc = $_GET['a'];
$filecrctxt = $filecrc.".dfh";
if (file_exists("./files/".$filecrctxt)) {
   $fh = fopen ("./files/".$filecrctxt,r);
   $thisline= explode('|', fgets($fh));
   if ($thisline[0]==$_GET['a'] && md5($thisline[2].$_SERVER['REMOTE_ADDR'])==$_GET['b'])
      $validdownload=$thisline;
   fclose($fh);
}
if($validdownload==0) {
?> <center><table style="margin-top:0px;width:790px;height:400px;"><tr><td style="border:1px #AAAAAA solid;height:100%;background-color:#FFFFFF;padding:20px;text-align:left;" valign=top>
<?
    echo "<center>$lang[inlink]</center>";
?></center></td></tr></table><p style="margin:3px;text-align:center"><?
    include("./footer.php");
    die();
}

$userip = $_SERVER['REMOTE_ADDR'];
$time = time();

$filesize = filesize("./storage/".$validdownload[0]);
$filesize = $filesize / 1048576;

if($filesize > $nolimitsize)
{
$newfile = "./downloader/".$userip.".dfh";
$f=fopen($newfile, "w");
fwrite ($f,$userip."|".$time."|");
fclose($f);
chmod($newfile,0777);
}


$validdownload[4] = time();

session_start();
if(isset($_SESSION['logged_in']) && $_SESSION['logged_in']==md5(md5($adminpass))) {
}
else {

// begin separate file mod
$newfile = "./files/$filecrc" . ".dfh";
$f=fopen($newfile, "w");
fwrite ($f,$validdownload[0]."|". $validdownload[1]."|". $validdownload[2]."|". $validdownload[3]."|". $validdownload[4]."|".($validdownload[5]+1)."|".$validdownload[6]."|".$validdownload[7]."|".$validdownload[8]."|\n");
fclose($f);
// end separate file mod
}

$speed_rate = 100;
//Speed is in KB/s (Kilobytes per second).

header('Cache-control: private');
header('Content-type: application/octetstream');
header('Content-Length: ' . filesize("./storage/".$validdownload[0]));
header('Content-Disposition: filename='.$validdownload[1]);

flush();

$dfile = fopen("./storage/".$validdownload[0], "r");

while (!feof($dfile)){
print fread($dfile, round($speed_rate * 1024));
flush();
sleep(1);
}

fclose($dfile);

?>


To adjust the speed rate of the download, modify the speed_rate variable.

Note: The above script might cause DFH to use more resources than normal.


Need to add ) in the last line of the code you gave me, and even after i added it - it has so many errors when i'm trying to download a file..