<?php
/**
 * @youtodesign-download
 */
//判断来源网址
//$host='www.youtodesign.com';
//if(isset($_SERVER['HTTP_REFERER'])&&strpos($_SERVER['HTTP_REFERER'], $host)!==false)
//{
	
	//来源于本网站 可以下
	require_once (dirname(__FILE__) . "/include/common.inc.php");
	include_once(dirname(__FILE__) ."/include/zip.class.php");
	include_once(dirname(__FILE__) ."/include/file_class.php");

    $GLOBALS['_arclistEnv'] = 'download';
	//得到下载id
	$downid=(intval($_GET['downid'])>0)?intval($_GET['downid']):0;
	if($downid>0)
	{
		$row = $dsql->GetOne("Select tarball From `#@__archives` Where id='".$downid."'");
		$downfile = dirname(__FILE__).$row['tarball'];
		if(file_exists($downfile))
        {
			$dsql->ExecuteNoneQuery("update `#@__archives` set downtimes=downtimes+1 WHERE id='".$downid."'");
			$filename = substr($downfile,(strrpos($downfile,'/')+1));
			$read=fopen($downfile,"r");
			$mm_type="application/octet-stream";
			header("Cache-Control: public, must-revalidate");
			header("Pragma: hack");
			header("Content-Type: " . $mm_type);
			header("Content-Length: " .(string)(filesize($downfile)) );
			header('Content-Disposition: attachment; filename="'.$filename.'"');
			echo fread($read,filesize($downfile));
			fclose($read);
			header("Content-Transfer-Encoding: binary\n");
			exit;
		}
	}
/*}
else
{
	echo 'false';
}*/


?>