<?php
define('IN_GATEWEI', TRUE);
require_once('./config.inc.php');
require_once('./engine/db_mysql.class.php');
$storedir=array(1=>"article",2=>"product",3=>"thread",4=>"reply");
$db = new db;

$db->connect($db_hostname,$db_username,$db_password,$db_name);
$fid=intval($_GET['fid']);
$q=$db->query("select * from g_attachments where fid = $fid");
if(!$attach = $db->fetch_array($q)){
	showmsg("附件不存在","index.php");
}
$attach['name']=iconv("UTF-8","GB2312//IGNORE",$attach['name']);
$downtime=$attach['downtimes']+1;
$filepath="clientdata/attachment/".$storedir[$attach['typeid']]."/".$attach['storename'];
$db->query("update g_attachments set downtimes = $downtime where fid =$fid");

header('Cache-control: max-age=31536000');
header('Expires: '.gmdate('D, d M Y H:i:s', time() + 31536000).' GMT');
header('Content-Encoding: none');
header('Content-Disposition: attachment; filename='.$attach['name']);
header('Content-Type: '.$attach['attachtype']);
@readfile($filepath);

?>