Location: PHPKode > projects > @1 File Store > download.php
<?
if(isset($_GET["id"]) && $_GET["id"]!="") {
 $fileid=$_GET["id"];

// Validate all inputs
// Added by SepedaTua on June 01, 2006 - http://www.sepedatua.info/
/********************** SepedaTua ****************************/

/* Fields:
$fileid
*/
$search = array ('@<script[^>]*?>.*?</script>@si',
                '@<[\/\!]*?[^<>]*?>@si',
                '@([\r\n])[\s]+@',
                '@&(quot|#34);@i',
                '@&(amp|#38);@i',
                '@&(lt|#60);@i',
                '@&(gt|#62);@i',
                '@&(nbsp|#160);@i',
                '@&(iexcl|#161);@i',
                '@&(cent|#162);@i',
                '@&(pound|#163);@i',
                '@&(copy|#169);@i',
                '@&#(\d+);@e');

$replace = array ('',
                 '',
                 '\1',
                 '"',
                 '&',
                 '<',
                 '>',
                 ' ',
                 chr(161),
                 chr(162),
                 chr(163),
                 chr(169),
                 'chr(\1)');

$ffileid = $fileid;

$fileid = preg_replace($search, $replace, $fileid);

if ($ffileid!=$fileid) { exit("Bad Request"); }

/************************ eod ******************************/

} else {
  exit("Bad request");
 }

if(!isset($_GET["sig"])) // direct download, no need to login
$MustLogin=1|2|4;
require_once("libs/header.php");
if(!isset($_GET["sig"])) // direct download, no need to login
$userlevel=$CurUser->getlevel();
$SQL="SELECT * FROM `".DB_PREFIX."file_list` WHERE `id`='".$fileid."'";
if(!$mysql->query($SQL))
{
 exit($mysql->error);
}
$download=$mysql->field("download");
$size=$mysql->field("filesize");
$filename=$mysql->field("filename");
$mffid = $mysql->field("folder_id"); // move from line 73. Fixed by niotech
if(!isset($_GET["sig"])){ // direct download, no need to login
$check=check_folder($mysql, $mysql->field("folder_id"), $userlevel);

if(!is_array($check))
{
 $smarty->assign("message", $check);
 $smarty->display("message.tpl");
 exit();
}
}

$fpath = " Index /";
function currentLocation( $fid ) {
	global $smarty, $fpath ;
	$SQL = mysql_query("SELECT folder_name, id, parent FROM fstore_folders WHERE id=$fid ");
	$row = mysql_fetch_array( $SQL );
	if( $row['parent'] == 0 ) 
		$location = " {$row['folder_name']} /";
	else {
		$location = " {$row['folder_name']} /";
		currentLocation( $row['parent'] );
	}
	$fpath .= $location ;
}
currentLocation( $mffid );
if(!isset($_GET["sig"])) // direct download, no need to login
$log->log("D", $CurUser->getid(), $fpath.' '.$filename);
else
	$log->log("D", NULL, $lang['direct_download'].': '.$fpath.' '.$filename);

// -- checking file signature -- (added by niotech)
if(isset($_GET["sig"])){ // direct download, no need to login
	$sig=$_GET["sig"];
	$f=fopen(UPLOAD_DIR.$download,"r");
	$buff=fread($f,$size);
	fclose($f);
	$sig2=md5($buff);
	
	if(strcmp($sig,$sig2)!=0){
		exit("Invalid download");
	}	
}
/********************** SepedaTua ****************************/
if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
	ini_set( 'zlib.output_compression','Off' );
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: private");
/************************ eod ******************************/
header("Content-type: application/force-download"); 
header("Content-disposition: attachment; filename=\"".$filename."\""); 
header("Content-Transfer-Encoding: binary"); 
header("Content-length: ".$size); 
readfile(UPLOAD_DIR.$download);
exit();
?>
Return current item: @1 File Store