Location: PHPKode > scripts > Download Tracker > kbdownload/kbdownload/download.php
<?php include "config.php"; ?>
<?php
if( isset($_REQUEST['downloadid']) )
{
$downloadid=$_REQUEST['downloadid'];

    $qrydownloadlist="SELECT * FROM scrdownload WHERE downloadid='$downloadid'";
	$rsldownloadlist=mysql_query($qrydownloadlist);
	$ndownloadlist = mysql_num_rows($rsldownloadlist);
	$arrdownloadlist =  mysql_fetch_row($rsldownloadlist);
	
	if($ndownloadlist!='0')
	{
    $downloadfile="files/$arrdownloadlist[8]$arrdownloadlist[9]"; 
    //Set the path to file
    //Extension can be specified in the Database also, if you want to have different extensions
    //header("Location: $downloadfile");
    //If you want the user to return back to the page then uncomment the above line 
    //and comment the line below
    echo "<meta http-equiv='refresh' content='1;URL=$downloadfile'>";
?>
<html>
<head>
<title>KB Download PHP Script!</title>
</head>
<body>

<table border="0" cellpadding="10" cellspacing="10" width="100%">
  <tr>
    <td valgin="center" algin="center">

<div align="center" valign="middle">
<table border="1" cellpadding="0" cellspacing="0" width="500px">
  <tr>
    <td width="100%" align="center">
   <?php
   echo "<b>You are downloading $arrdownloadlist[1]</b>";
   ?>
&nbsp;</td>
  </tr>
  <tr>
    <td width="100%">
    <?php
$dtetmenow= date("Y-m-d H:i:s" , time());
$tmenow= date(time());
$dtetdy= date("Y-m-d" , time());   
$montdy= date("m" , time());
$daytdy= date("d" , time());
$dteystdy= date("Y-m-d" , mktime(0,0,0,$montdy,$daytdy-1));
$weekdaytdy= date("w" , time());
$dteweek= date("Y-m-d" , mktime(0,0,0,$montdy,$daytdy-$weekdaytdy));
$dtemonth= date("Y-m-d" , mktime(0,0,0,$montdy,1));

		$downloadttl=$arrdownloadlist[3];
		$downloadttl++;
		$downloadttlupd = mysql_query ("UPDATE scrdownload SET 
		downloadttl='$downloadttl',downloadlstdte='$dtetmenow' WHERE downloadid='$downloadid' ");


$downloaddte= date('Y-m-d',strtotime($arrdownloadlist[2]));
if($downloaddte!=$dtetdy)
{
//Code for Today
$downloadtdyupd = mysql_query ("UPDATE scrdownload SET 
downloadtdy='1' WHERE downloadid='$downloadid' ");

//Code for Yesterday
if($downloaddte==$dteystdy && $arrdownloadlist[4]!='0')
{
$downloadystdyupd = mysql_query ("UPDATE scrdownload SET 
downloadystdy='$arrdownloadlist[4]' WHERE downloadid='$downloadid' ");
}
elseif($downloaddte<$dteystdy)
{
$downloadystdyupd = mysql_query ("UPDATE scrdownload SET 
downloadystdy='0' WHERE downloadid='$downloadid' ");
}

//Code for Week
if($downloaddte>=$dteweek)
{
$newdownloadweek=$arrdownloadlist[6]+1;
$downloadweekupd = mysql_query ("UPDATE scrdownload SET 
downloadweek='$newdownloadweek' WHERE downloadid='$downloadid' ");
}
elseif($downloaddte<$dteweek)
{
$downloadweekupd = mysql_query ("UPDATE scrdownload SET 
downloadweek='1' WHERE downloadid='$downloadid' ");
}

//Code for Month
if($downloaddte>=$dtemonth)
{
$newdownloadmonth=$arrdownloadlist[7]+1;
$downloadmonthupd = mysql_query ("UPDATE scrdownload SET 
downloadmonth='$newdownloadmonth' WHERE downloadid='$downloadid' ");
}
elseif($downloaddte<$dtemonth)
{
$downloadmonthupd = mysql_query ("UPDATE scrdownload SET 
downloadmonth='1' WHERE downloadid='$downloadid' ");
}

}
else
{
//Code for Today
$newdownloadtdy=$arrdownloadlist[4]+1;
$downloadtdyupd = mysql_query ("UPDATE scrdownload 
SET downloadtdy='$newdownloadtdy' WHERE downloadid='$downloadid' ");

//Code for Week
if($downloaddte>=$dteweek)
{
$newdownloadweek=$arrdownloadlist[6]+1;
$downloadweekupd = mysql_query ("UPDATE scrdownload SET 
downloadweek='$newdownloadweek' WHERE downloadid='$downloadid' ");
}

//Code for Month
if($downloaddte>=$dtemonth)
{
$newdownloadmonth=$arrdownloadlist[7]+1;
$downloadmonthupd = mysql_query ("UPDATE scrdownload SET 
downloadmonth='$newdownloadmonth' WHERE downloadid='$downloadid' ");
}

}

echo "Please wait for few seconds for download to start.<br>
If your download doesn't start in 5 seconds,<br>
then <a href='$downloadfile' title='Download $arrdownloadlist[1] here, if the download has not started'>Click Here</a> to download <b>$arrdownloadlist[1]</b>
";
?>&nbsp;</td>
  </tr>    
</table>
</div>


    </td>
  </tr>
</table>

</body>
</html>
<?php
	}
	else
	{
echo "The Download file you are trying does not exist<br>";
	}
}
else
{
echo "Some error Occured. Try again!<br>";
}
?>
Return current item: Download Tracker