hi @ all
Need help with php script..its a download script
when i use it it cant download any files couse the script cant get the download file size.
I tryed really lot things.
I am thinking that the problem is
on "$header = getallheaders();"
when i remove that i can download with a download manager
but when i try to start the download without a downoad manager its just waiting...🙁
anyway here is the code..hope someone can help me:
as far readed from php pages the problem is that the php module is not installed at my host..
is there another way to let this code work..? or maybe something like this?
<?php
require './functions.php';
register_shutdown_function('bye_bye');
ReadConfig ('DEVINFO, MAIN, WHITELIST, BLACKLIST, REFLIST');
header ("Expires: Tue, 1 Jan 1980 00:00:00 GMT");
header ("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header ("Cache-Control: no-store, no-cache, must-revalidate");
header ("Cache-Control: post-check=0, pre-check=0", false);
header ("Pragma: no-cache");
header ("X-Powered-By: Antileech");
$IP = GetIP();
$whitelisted = WhiteList($IP);
if (!$whitelisted && BlackList($IP)) {
Message ('You were added to blacklist. Go fuck yourself...', $MAIN['url']);
}
if (!$whitelisted && !CheckReferer()) {
Message ('This page is only avaliable from the '.$MAIN['url'].' site, where you\'re being redirected...', $MAIN['url']);
}
mysql_connect($MAIN['db_address'], $MAIN['db_username'], $MAIN['db_password']);
mysql_select_db($MAIN['db_database']);
ClearTimeouted();
$return = GetParams();
if (sizeof($return) != 2) {
Message ('Wrong query!');
}
$session = $return[0];
if (!empty($MAIN['maxtotalthreads'])) {
$Query = "SELECT SUM(threads) AS `total` FROM ".$MAIN['db_table'];
$Res = mysql_query($Query);
list($total) = mysql_fetch_array($Res);
if ($total >= $MAIN['maxtotalthreads']) {
Message ('Unfortunately, the server load is too high at the moment. This server can handle only '.$MAIN['maxtotalthreads'] .' threads simultaneous. Please, try again later.');
}
}
$Query = "SELECT SUM(threads) FROM ".$MAIN['db_table']." WHERE ip = '".$IP."'";
$Result = mysql_query($Query);
if (mysql_num_rows($Result)) {
list($threads) = mysql_fetch_array($Result);
if ($threads >= $MAIN['maxthreadspersession']) {
Message ('You cannot download more than '.$MAIN['maxthreadspersession'].' threads at the same time!', $MAIN['url']);
}
}
$Query = "SELECT * FROM ".$MAIN['db_table']." WHERE session = '".addslashes($session)."' AND ip = '".$IP."'";
$Result = mysql_query($Query);
if (!mysql_num_rows($Result)) {
Message ('Your session expired or you specified wrong session name.', $MAIN['url']);
}
$info = mysql_fetch_assoc($Result);
$Query = "UPDATE ".$MAIN['db_table']." SET threads = threads + 1 WHERE session = '".addslashes($session)."'";
$Result = mysql_query($Query);
$is_increased = true;
$fullpath = $MAIN['filepath'].$info['category'].'/'.$info['file'];
$size = filesize($fullpath);
$fp = fopen($fullpath, 'r');
header ('Accept-Ranges: bytes');
header ('Content-Type: application/force-download');
header ('Connection: close');
$header = getallheaders();
if (isset($header['Range'])) {
header('HTTP/1.0 206 Partial Content');
$range = $header['Range'];
$r = explode('=', $range);
list($from) = explode('-', $r[1]);
$length = $size - $from;
$s_start = $size - $length;
$s_end = $size - 1;
fseek($fp, $s_start);
header ('Content-Range: bytes '.$s_start.'-'.$s_end.'/'.$size);
header ('Content-Length: '.$length);
} else {
header('Content-Length: '. $size);
}
set_time_limit(0);
ob_implicit_flush(true);
if (empty($MAIN['maxkbps'])) {
while (!feof($fp)) {
print (fread($fp, 10240));
if (connection_aborted()) {
break;
}
}
} else {
$koef = 10;
$readlen = intval(1024 * $MAIN['maxkbps'] / $koef);
$waittime = intval(1000000 / $koef);
while (!feof($fp)) {
if (connection_aborted()) {
break;
}
print (fread($fp, $readlen));
usleep($waittime);
}
}
fclose($fp);
?>