<?php
/*-------------------------------------
	版权所有：南京牛昆网络科技有限公司（TEL-15896098989）
	程序版本：1.0
	更新日期：2015-04-17   
-------------------------------------*/
class attachment
{
	private $db;
	private $table;

	function __construct()
	{
		global $db;
		$this->db=$db;
		$this->table=LA_PRE.'attchment';
	}

	function attchment_delete($userid=0,$modelid=1)
	{
		$userid=intval($userid);
		$modelid=intval($modelid);

		$r=$this->db->fetch_all("SELECT * FROM `$this->table` WHERE `$this->table`.`userid`=$userid AND `$this->table`.`modelid`=$modelid");
		foreach($r as $_r)
		{
			$filepath=str_replace('\\','/',$_r['filepath']);
			$filepath=SYSTEM_ROOT.(substr($filepath,0,1)=='/'?substr($filepath,1):$filepath);
			if(is_file($filepath))
			{
				@unlink($filepath);
			}
		}

		$this->db->query("DELETE FROM `$this->table` WHERE `$this->table`.`userid`=$userid AND `$this->table`.`modelid`=$modelid",true);
		return true;
	}
}
?>
