<?php
/*
===========================注册模块控制器
*/
class cls_tab_other_upload extends cls_base_table
{
	private $obj_db;
	private $config=array(),$arr_cfg_other=array();
	//构造函数
	function __construct()
	{
		parent::__construct();
		global $obj_db,$obj_ctl_user,$obj_tab_sys_config;
		$arr_cfg_other=$obj_tab_sys_config->get_model("other");
		$this->obj_db=$obj_db;
		$this->tab_file=DB_PRE."file";
		$lng_user_id=$obj_ctl_user->id;
		$this->cfg_upload["dir"]="/upload";//上传根目录
		if(isset($arr_cfg_other["dir"])) $this->cfg_upload["dir"]=$arr_cfg_other["dir"];
		$this->config["dir_root"]=WEB_ROOT;


		//初始系统设置
		$this->cfg_upload["uname"]="";//上传用户
		$this->cfg_upload["uid"]=0;//上传用户
		$this->cfg_upload["allow"]=1;//是否允许上传,1表求允许，非1表示不允许
		$this->cfg_upload["onlogin"]=1;//上传是否需要登陆,1表求允许，非1表示不允许
		$this->config["path"]=$this->cfg_upload["dir"]."/user/".$lng_user_id;//上传路径
		$this->cfg_upload["count"]=5;//支持一次最多文件上传数
		$this->cfg_upload["filesize"]="";//单个文件不能超过的大小,0表求不限
		$this->cfg_upload["filesize_x"]="";
		$this->cfg_upload["spacesize"]="";//可用空间大小
		$this->cfg_upload["allowext"]=array();//允许上传的文件扩展名,数组
		$this->cfg_upload["noallowext"]=array();//不允许上传的文件扩展名,数组
		if(isset($arr_cfg_other["upload_allow"])) $this->cfg_upload["allow"]=intval($arr_cfg_other["upload_allow"]);
		if(isset($arr_cfg_other["upload_onlogin"])) $this->cfg_upload["onlogin"]=intval($arr_cfg_other["upload_onlogin"]);
		if(isset($arr_cfg_other["upload_count"])) $this->cfg_upload["count"]=intval($arr_cfg_other["upload_count"]);
		if(isset($arr_cfg_other["upload_filesize"])) {
			$this->cfg_upload["filesize_x"]=$this->cfg_upload["filesize"];
			$this->cfg_upload["filesize"]=intval($arr_cfg_other["upload_filesize"])*1024*1024;
		}
		if(isset($arr_cfg_other["upload_allowext"])) $this->cfg_upload["allowext"]=$arr_cfg_other["upload_allowext"];
		if(isset($arr_cfg_other["upload_noallowext"])) $this->cfg_upload["noallowext"]=$arr_cfg_other["upload_noallowext"];
		if(isset($obj_ctl_user)) $this->cfg_upload["uid"]=$obj_ctl_user->id;

	}
	//保存
	function on_save($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0,"path"=>"");
		(!isset($arr_fields["upload_id"]))? $arr_fields["upload_id"]=0:$arr_fields["upload_id"]=intval($arr_fields["upload_id"]);
		//保存操作
		$lng_id=$arr_fields["upload_id"];
		unset($arr_fields["upload_id"]);//释放id

		$arr_fields["upload_updatetime"]=TIME;
		if($lng_id<1){
			$arr_fields["upload_addtime"]=TIME;
			$arr_return=self::_insert($arr_fields);
		}else{
			if((!isset($arr_fields["upload_path"])||$arr_fields["upload_path"]=="")&&isset($arr_fields["upload_name"])){
				$arr_fields["upload_path"]=self::get_upload_url($arr_fields["upload_name"]);
			}
			$str_where="upload_id='".$lng_id."'";
			$arr_return=self::_update($arr_fields,$str_where);
			$arr_return["id"]=$lng_id;
		}
		if(isset($arr_fields["upload_path"])) $arr_return["path"]=$arr_fields["upload_path"];
		return $arr_return;
	}
	//添加
	private function _insert($arr_fields)
	{
		if(!isset($arr_fields["upload_path"])||$arr_fields["upload_path"]=="") return "文件路径不能为空！";
		if(!isset($arr_fields["upload_ext"])){
			$arr_fields["upload_ext"]=get_file_ext($arr_fields["upload_path"]);
		}
		$arr_fields["upload_type"]=self::get_upload_type($arr_fields["upload_path"],$arr_fields["upload_ext"]);
		$arr_return=parent::on_insert(DB_PRE."other_upload",$arr_fields);
		return $arr_return;
	}
	//修改
	private function _update($arr_fields,$msg_where)
	{
		$arr_return=parent::on_update(DB_PRE."other_upload",$arr_fields,$msg_where);
		return $arr_return;
	}
	//删除
	function on_del($arr_id)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		$arr_path=array();
		$sql="select * from ".DB_PRE."other_upload"." where upload_id in(".$str_id.")";
		$result = $this->obj_db->query($sql);
		while($rs = $this->obj_db->fetch_array($result))
		{
			$arr_path[]=$rs;
		}

		$arr_return=parent::on_del(DB_PRE."other_upload","upload_id in(".$str_id.")");

		if($arr_return["err"]==""&&count($arr_path)>0){
			foreach($arr_path as $item)
			{
				$str_path=get_real_path($this->config["dir_root"],$item["upload_path"]);
				file_delete($str_path);
			}
		}

		return $arr_return;
	}
	function get_upload_type($msg_ext)
	{
		if(is_pic($msg_ext)) return "pic";
		if(is_flash($msg_ext)) return "flash";
		if(is_medio($msg_ext)) return "medio";
		return "other";
	}
	function get_config($msg_v)
	{
		if(isset($this->config[$msg_v])) return $this->config[$msg_v];
	}
	function on_file_copy($source_id,$to_dirid){
		$arr_return=array("err"=>"");
		$sql="select * from ".DB_PRE."other_upload"." where upload_id='".$source_id."'";
		$result = $this->obj_db->query($sql);
		if($obj_rs = $this->obj_db->fetch_array($result))
		{
			$arr_upload=$obj_rs;
		}else{
			$arr_return["err"]="原文件不存在！";
			return $arr_return;
		}
		if($to_dirid>0){
			$sql="select * from ".DB_PRE."other_upload_folder where folder_id='".$to_dirid."' and folder_user_id='".$arr_upload["upload_user_id"]."'";
			$result = $this->obj_db->query($sql);
			if($obj_rs = $this->obj_db->fetch_array($result))
			{
				$arr_folder=$obj_rs;
			}else{
				$arr_return["err"]="目标文件夹不存在！";
				return $arr_return;
			}
		}
		//复制文件
		$msg_todir=self::get_real_path($arr_folder["folder_path"]);
		$msg_frompath=get_real_path("",$arr_upload["upload_path"]);
		$msg_name=$arr_upload["upload_name"];
		$msg_recopy=file_copy($msg_frompath,$msg_name,$msg_todir,$msg_isover=0);
		if($msg_recopy["err"]!=""){
			$msg_return["err"]=$msg_recopy["err"];
			return $msg_return;
		}
		if($msg_recopy["name"]!=$arr_upload["upload_name"]) $arr_upload["upload_name"]=$msg_recopy["name"];
		$arr_upload["upload_path"]=format_path($this->config["path"]."/".$arr_folder["folder_path"]."/".$arr_upload["upload_name"]);
		//保存文件
		$arr_fields=array();
		$arr_fields["upload_user_id"]=$arr_upload["upload_user_id"];
		$arr_fields["upload_folder_id"]=$arr_folder["folder_id"];
		$arr_fields["upload_name"]=$arr_upload["upload_name"];
		$arr_fields["upload_ext"]=$arr_upload["upload_ext"];
		$arr_fields["upload_size"]=$arr_upload["upload_size"];
		$arr_fields["upload_path"]=$arr_upload["upload_path"];
		$arr_fields["upload_addtime"]=TIME;
		$arr_return=self::on_save($arr_fields);
		return $arr_return;
	}
	function on_folder_copy($source_id,$to_dirid){
		$arr_return=array("err"=>"");
		$sql="select * from ".DB_PRE."other_upload_folder where folder_id='".$source_id."'";
		$result = $this->obj_db->query($sql);
		if($obj_rs = $this->obj_db->fetch_array($result))
		{
			$arr_source=$obj_rs;
		}else{
			$arr_return["err"]="原文件夹不存在！";
			return $arr_return;
		}
		$arr_folder["folder_path"]="";
		if($to_dirid>0){
			$sql="select * from ".DB_PRE."other_upload_folder where folder_id='".$to_dirid."' and folder_user_id='".$arr_source["folder_user_id"]."'";
			$result = $this->obj_db->query($sql);
			if($obj_rs = $this->obj_db->fetch_array($result))
			{
				$arr_folder=$obj_rs;
			}else{
				$arr_return["err"]="目标文件夹不存在！";
				return $arr_return;
			}
		}
		//创建文件夹
		$arr_fields=array();
		$arr_fields["folder_name"]=$arr_source["folder_name"];
		$arr_fields["folder_pid"]=$to_dirid;
		$arr_return=self::on_save_folder($arr_fields);
		if($arr_return["err"]==""&&$arr_return["id"]>0){
			//复制文件
			$sql="select * from ".DB_PRE."other_upload where upload_folder_id='".$source_id."'";
			$result = $this->obj_db->query($sql);
			while($obj_rs = $this->obj_db->fetch_array($result))
			{
				self::on_file_copy($obj_rs["upload_id"],$arr_return["id"]);
			}
			$sql="select * from ".DB_PRE."other_upload_folder where folder_pid='".$source_id."'";
			$result = $this->obj_db->query($sql);
			while($obj_rs = $this->obj_db->fetch_array($result))
			{
				self::on_folder_copy($obj_rs["folder_id"],$arr_return["id"]);
			}
		}
		return $arr_return;
	}
	function on_folder_rename($msg_id,$msg_name){
		$arr_return=array("err"=>"");
		$str_sql="select * from ".DB_PRE."other_upload_folder where folder_id='".$msg_id."'";
		$obj_result  = $this->obj_db->query($str_sql);
		if($obj_rs=$this->obj_db->fetch_array($obj_result)){
			$arr_folder=$obj_rs;
		}else{
			$arr_return["err"]="原文件夹不存在！";
			return $arr_return;
		}
		$str_sql="select * from ".DB_PRE."other_upload_folder where folder_pid='".$arr_folder["folder_pid"]."' and folder_name='".$msg_name."' and folder_id!='".$msg_id."'";
		$obj_result  = $this->obj_db->query($str_sql);
		if($obj_rs=$this->obj_db->fetch_array($obj_result)){
			$arr_return["err"]="重命名失败，新名称与现有文件夹重名！";
			return $arr_return;
		}
		$str_old_path=self::get_real_path($arr_folder["folder_path"]);
		$arr_folder["folder_name"]=$msg_name;
		$arr_return=self::on_save_folder($arr_folder);
		if($arr_return["err"]==""){
			$str_new_path=self::get_real_path($arr_return["path"]);
			$str_msg=dir_rename($str_old_path,$str_new_path);
		}
		return $arr_return;
	}
	function on_file_rename($msg_id,$msg_name){
		$arr_return=array("err"=>"");

		$arr_msg=chk_file_name($msg_name);
		if($arr_msg["err"]!=""){
			$arr_return["err"]=$arr_msg["err"];
			return $arr_return;
		}
	
		//检查扩展名是否允许
		$str_ext=get_file_ext($msg_name);
		$msg_info=self::upload_chk_allow_ext($str_ext);
		if($msg_info!=""){
			$arr_return["err"]=$msg_info;
			return $arr_return;
		}

		$str_sql="select * from ".DB_PRE."other_upload where upload_id='".$msg_id."'";
		$obj_result  = $this->obj_db->query($str_sql);
		if($obj_rs=$this->obj_db->fetch_array($obj_result)){
			$arr_upload=$obj_rs;
		}else{
			$arr_return["err"]="原文件不存在！";
			return $arr_return;
		}
		if($arr_upload["upload_name"]==$msg_name) return $arr_return;
		$str_sql="select * from ".DB_PRE."other_upload where upload_folder_id='".$arr_upload["upload_folder_id"]."' and upload_name='".$msg_name."' and upload_id!='".$msg_id."'";
		$obj_result  = $this->obj_db->query($str_sql);
		if($obj_rs=$this->obj_db->fetch_array($obj_result)){
			$arr_return["err"]="重命名失败，新名称与现有文件重名！";
			return $arr_return;
		}
		$arr_fields=array();
		$arr_fields["upload_id"]=$arr_upload["upload_id"];
		$str_old_path=get_real_path("",$arr_upload["upload_path"]);
		$arr_fields["upload_name"]=$msg_name;
		$arr_return=self::on_save($arr_fields);
		if($arr_return["err"]==""){
			$str_new_path=get_real_path("",$arr_return["path"]);
			$str_msg=file_rename($str_old_path,$str_new_path);
		}
		return $arr_return;
	}
	//保存上传目录
	function on_save_folder($arr_fields=array())
	{
		global $obj_ctl_user;
		$arr_return=array("err"=>"","id"=>0,"path"=>"");
		(!isset($arr_fields["folder_id"]))? $arr_fields["folder_id"]=0:$arr_fields["folder_id"]=intval($arr_fields["folder_id"]);
		$lng_id=$arr_fields["folder_id"];
		(!isset($arr_fields["folder_pid"]))? $arr_fields["folder_pid"]=0:$arr_fields["folder_pid"]=intval($arr_fields["folder_pid"]);

		$arr_fields["folder_user_id"]=$obj_ctl_user->id;

		$str_sql="select * from ".DB_PRE."other_upload_folder where folder_id='".$arr_fields["folder_pid"]."'";
		$obj_result  = $this->obj_db->query($str_sql);
		if($obj_rs=$this->obj_db->fetch_array($obj_result)){
			if($obj_rs["folder_pids"]!="") $obj_rs["folder_pids"].=",";
			$arr_fields["folder_pids"]=$obj_rs["folder_pids"].$arr_fields["folder_pid"];
			$arr_fields["folder_path"]=$obj_rs["folder_path"]."/".$arr_fields["folder_name"];
		}else{
			$arr_fields["folder_path"]=$arr_fields["folder_name"];
		}

		unset($arr_fields["folder_id"]);//释放id
		if($lng_id<1){
			//检查目录是否已存在
			$str_sql="select folder_id from ".DB_PRE."other_upload_folder where folder_pid='".$arr_fields["folder_pid"]."' and folder_name='".$arr_fields["folder_name"]."'";
			$obj_result  = $this->obj_db->query($str_sql);
			if($obj_rs=$this->obj_db->fetch_array($obj_result)){
				$arr_return["err"]="目录已经存在！";
				return $arr_return;
			}
			//创建物理目录
			$str_path=self::get_real_path($arr_fields["folder_path"]);
			$return_val=dir_create($str_path);

			$arr_fields["folder_addtime"]=TIME;
			$arr_return=parent::on_insert(DB_PRE."other_upload_folder",$arr_fields);
			if($arr_return["err"]==""){
				$str_sql="select folder_id from ".DB_PRE."other_upload_folder where folder_pid='".$arr_fields["folder_pid"]."' and folder_name='".$arr_fields["folder_name"]."' and folder_addtime='".TIME."'";
				$obj_result  = $this->obj_db->query($str_sql);
				if($obj_rs=$this->obj_db->fetch_array($obj_result)){
					$arr_return["id"]=$obj_rs["folder_id"];
				}
			}
		}else{
			$str_where="folder_id='".$lng_id."'";
			$arr_return=parent::on_update(DB_PRE."other_upload_folder",$arr_fields,$str_where);
			$arr_return["id"]=$lng_id;
		}
		$arr_return["path"]=$arr_fields["folder_path"];
		return $arr_return;
	}
	function get_real_path($msg_path){
		$str_path=get_real_path($this->config["dir_root"].$this->config["path"],$msg_path);
		return $str_path;
	}
	function on_folder_del($arr_id)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		
		//查看子目录，有则删除
		$sql="select * from ".DB_PRE."other_upload_folder where folder_pid in(".$str_id.")";
		$result = $this->obj_db->query($sql);
		$arr_child_ids=array();
		while($rs = $this->obj_db->fetch_array($result))
		{
			$arr_child_ids[]=$rs["folder_id"];
		}
		if(count($arr_child_ids)>0){
			self::on_folder_del($arr_child_ids);
		}

		$sql="select * from ".DB_PRE."other_upload_folder where folder_id in(".$str_id.")";
		$result = $this->obj_db->query($sql);
		while($rs = $this->obj_db->fetch_array($result))
		{
			$arr_path[]=$rs;
		}

		$arr_return=parent::on_del(DB_PRE."other_upload_folder","folder_id in(".$str_id.")");

		if($arr_return["err"]==""&&count($arr_path)>0){
			//删除文件
			$arr_upload_ids=array();
			$sql="select * from ".DB_PRE."other_upload where upload_folder_id in(".$str_id.")";
			$result = $this->obj_db->query($sql);
			while($rs = $this->obj_db->fetch_array($result))
			{
				$arr_upload_ids[]=$rs["upload_id"];
			}
			if(count($arr_upload_ids)>0){
				self::on_del($arr_upload_ids);
			}
			foreach($arr_path as $item)
			{
				$str_path=self::get_real_path($item["folder_path"]);
				$str_return=dir_delete($str_path);
			}
		}

		return $arr_return;
	}
	function on_upload()
	{
		$arr_return=array("err"=>"");
		//检查是否可以上传
		$msg_info=self::upload_chk_allow();
		if($msg_info!=""){
			$arr_return["err"]=$msg_info;
			return $arr_return;
		}
		global $obj_db;
		$lng_upload_size=0;
		for($i=1;$i<=$this->cfg_upload["count"];$i++)
		{
			if(!isset($_FILES["file_".$i]))
			{	
				continue;
			}
			if($_FILES["file_".$i]["size"]<10) continue;
			$lng_upload_size+=$_FILES["file_".$i]["size"];
			//检查上传空间是否够用，0表示不限
			$msg_info=self::upload_chk_space_size($lng_upload_size);
			if($msg_info!=""){
				$arr_return["err"]=$msg_info;
				return $arr_return;
			}
			//上传单个文件的大小,以M为单位，0表示不限
			$msg_info=self::upload_chk_upload_size($_FILES["file_".$i]["size"]);
			if($msg_info!=""){
				$arr_return["err"]=$msg_info;
				return $arr_return;
			}

			//检查扩展名是否允许
			$str_ext=get_file_ext($_FILES["file_".$i]["name"]);
			$msg_info=self::upload_chk_allow_ext($str_ext);
			if($msg_info!=""){
				$arr_return["err"]=$msg_info;
				return $arr_return;
			}

			//获取上传路径及名称
			$str_name=$_FILES["file_".$i]["name"];
			$str_path=self::get_upload_path($str_name,$str_ext);
			move_uploaded_file($_FILES['file_'.$i]['tmp_name'],$str_path);
			if(is_file($str_path)){
				$arr_fields=array();
				$arr_fields["upload_user_id"]=$this->cfg_upload["uid"];
				$arr_fields["upload_folder_id"]=$this->cfg_upload["folder_id"];
				$arr_fields["upload_name"]=$str_name;
				$arr_fields["upload_ext"]=$str_ext;
				$arr_fields["upload_size"]=$_FILES["file_".$i]["size"];
				$arr_fields["upload_path"]=self::get_upload_url($str_name);
				$arr_fields["upload_addtime"]=TIME;
				$arr_return=self::on_save($arr_fields);
				//如果是图片的话,生成缩图
				self::on_upload_pic($str_path,$str_name);
			}
		}
		return $arr_return;
	}
	function upload_chk_allow()
	{
		global $obj_ctl_user;
		if(isset($this->cfg_upload["allow"])&&intval($this->cfg_upload["allow"])!=1) return "系统关闭了上传功能！";

		if(isset($this->cfg_upload["onlogin"])&&intval($this->cfg_upload["onlogin"])==1)
		{
			if(!isset($obj_ctl_user)) return "系统错误，未定义用户变量！";
			if(!$obj_ctl_user->is_login()) return "需要登陆才能进行上传操作！";
		}
		if(isset($this->config["allow"])&&intval($this->config["allow"])!=1) return "您没有上传的权限！";

	}
	function set_folder_id($msgid){
		$str_sql="select folder_id,folder_path from ".DB_PRE."other_upload_folder where folder_id='".$msgid."' and folder_user_id='".$this->cfg_upload["uid"]."'";
		$obj_result  = $this->obj_db->query($str_sql);
		$str_x="";
		if(strlen($this->config["path"])>0) $str_x=substr($this->config["path"],-1);
		if($this->config["path"]==""||($str_x!="/" && $str_x!="\\")) $this->config["path"].="/";
		if($obj_rs=$this->obj_db->fetch_array($obj_result)){
			$this->config["path"]=$this->config["path"].$obj_rs["folder_path"];
			$this->cfg_upload["folder_id"]=$msgid;
		}else{
			$this->cfg_upload["folder_id"]=0;
		}
	}
	function upload_chk_space_size($msgsize)
	{
		if(isset($this->cfg_upload["spacesize"]))
		{
			if($msgsize>intval($this->cfg_upload["spacesize"])&&intval($this->cfg_upload["spacesize"])>1) return "系统上传空间不够";
		}
		if(isset($this->config["spacesize"]))
		{
			if($msgsize>intval($this->config["spacesize"])&&intval($this->config["spacesize"])>1) return "上传空间不够";
		}
		return "";
	}
	function upload_chk_upload_size($msgsize)
	{
		if(isset($this->cfg_upload["filesize"]))
		{
			if($msgsize>intval($this->cfg_upload["filesize"])&&intval($this->cfg_upload["filesize"])>1) return "系统上传单个文件不能超过".format_uploadsize($this->cfg_upload["filesize_x"],"M")."(M)";

		}
		return "";
	}
	//检查扩展名
	function upload_chk_allow_ext($msg_ext)
	{
		$msg_ext=strtolower($msg_ext);
		if(substr($msg_ext,0,1)==".") $msg_ext=substr($msg_ext,1);
		if(!isset($this->cfg_upload["allowext"])||!is_array($this->cfg_upload["allowext"])) return "系统错误，未定义allowext变量！";
		if(!in_array($msg_ext,$this->cfg_upload["allowext"]))
		{
			return "系统不允许上传扩展名为".$msg_ext."的文件！";
		}
		if(in_array($msg_ext,$this->cfg_upload["noallowext"]))
		{
			return "系统不允许上传扩展名为".$msg_ext."的文件！";
		}
		if(isset($this->config["allowext"])&&is_array($this->config["allowext"])){
			if(!in_array($msg_ext,$this->config["allowext"]))
			{
				return "您无权上传该类型的文件！";
			}
		}
		if(isset($this->config["noallowext"])&&is_array($this->config["noallowext"])){
			if(in_array($msg_ext,$this->config["noallowext"]))
			{
				return "您无权上传该类型的文件！";
			}
		}
		return "";
	}

	function get_upload_path($msg_name,$msg_ext)
	{
		$str_dir=get_real_path($this->config["dir_root"],$this->config["path"]);
		if(!is_dir($str_dir)){
			dir_create($str_dir);
		}
		//$str_path=$str_dir."/".$msg_name;
		$str_path=format_path($str_dir."/".$msg_name);
		return $str_path;
	}
	function on_upload_pic($msg_path,$msg_name)
	{
		global $obj_db;
		require_once(SYS_ROOT. '/cls_ctl/ctl.pic.php');
		if(!is_pic($msg_path)) return;
		$obj_ctl_pic=new cls_ctl_pic;
		$obj_ctl_pic->on_watermark($msg_path);
		if(isset($_POST["smallpic"]) && intval($_POST["smallpic"])==1)
		{
			$str_name=basename($msg_path);
			if($msg_name!="")$str_name=$msg_name;
			$str_ext=get_file_ext($msg_path);
			$str_name=get_upload_name($str_name,$str_ext)."(略).".$str_ext;
			$str_dir=dirname($msg_path);
			$str_new_path=$str_dir."/".$str_name;
			$msg_info=$obj_ctl_pic->on_resize($msg_path,$str_new_path);
			if(is_file($str_new_path))
			{
				$arr_upload=get_file_perms($str_new_path);
				$arr_fields=array();
				$arr_fields["upload_user_id"]=$this->cfg_upload["uid"];
				$arr_fields["upload_folder_id"]=$this->cfg_upload["folder_id"];
				$arr_fields["upload_name"]=$str_name;
				$arr_fields["upload_ext"]=$arr_upload["ext"];
				$arr_fields["upload_size"]=$arr_upload["size"];
				$arr_fields["upload_path"]=self::get_upload_url($str_name);
				$arr_fields["upload_addtime"]=TIME;
				$msg_info=self::on_save($arr_fields);
			}
		}
	}
	function on_upload_web($msg_url)
	{
		//检查是否可以上传
		$arr_return=array("err"=>"");
		$msg_info=self::upload_chk_allow();
		if($msg_info!=""){
			$arr_return["err"]=$msg_info;
			return $arr_return;
		}
		//if(@upload($msg_url)==FALSE) return "网址无效！";
		if(!exists_remote_file($msg_url)) return "网址无效!";
		$str_uploadname=basename($msg_url);
		//检查扩展名是否允许
		$str_ext=get_file_ext($str_uploadname);
		$msg_info=self::upload_chk_allow_ext($str_ext);
		if($msg_info!=""){
			$arr_return["err"]=$msg_info;
			return $arr_return;
		}

		$data=file_get_contents($msg_url);
		$str_path=self::get_upload_path($str_uploadname,$str_ext);
		file_put_contents($str_path,$data);
		if(is_file($str_path)){
			$arr_upload=get_file_perms($str_path);
			$arr_fields=array();
			$arr_fields["upload_user_id"]=$this->cfg_upload["uid"];
			$arr_fields["upload_folder_id"]=$this->cfg_upload["folder_id"];
			$arr_fields["upload_name"]=$str_uploadname;
			$arr_fields["upload_ext"]=$arr_upload["ext"];
			$arr_fields["upload_size"]=$arr_upload["size"];
			$arr_fields["upload_path"]=self::get_upload_url($str_uploadname);
			$arr_fields["upload_addtime"]=TIME;
			self::on_save($arr_fields);
			//如果是图片的话,生成缩图
			self::on_upload_pic($str_path,$str_uploadname);
		}else{
			$arr_return["err"]="上传失败！";
		}
		return $arr_return;

	}
	function get_upload_url($msg_name)
	{
		if($msg_name=="") return "";
		$str_path=$this->config["path"]."/".$msg_name;
		$str_path=format_path($str_path);
		return $str_path;
	}

}
?>