<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class mvedio_fileAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);	
		$miceSession = new session();
		
		$sort=12;
		$_msg1 = '';
		$_msg2 = '';
		$filenames = '';
		$f_type=strtolower(MICE_UPLOAD_FILE_NAME);
		$file_size_max=MICE_UPLOAD_FILE_SIZE;
		$overwrite = 0;						//是否允许覆盖相同文件,1:允许,0:不允许 
		$f_input="Files";					//设置上传域名称
		$attdir=str_replace(array("{Y}","{M}","{D}"),array(date('Y'),date('n'),date('j')),MICE_UPLOAD_FILE_DIR);					//文件上传的路径
		if(!mkdirs($attdir)){
			echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><script>alert('对不起,".$attdir."目录不存在且不能建立该目录,文件上传失败!')</script>"; 
		}
			$count=0;
			foreach($_FILES[$f_input]["error"] as $key => $error){
				$count++;
				$up_error="no"; 
				if ($error == UPLOAD_ERR_OK){ 
					$f_name=$_FILES[$f_input]['name'][$key];//获取上传源文件名 
					$uploadfile=$uploaddir.strtolower(basename($f_name)); 
					 
					$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
					$tmp_type=strtolower($tmp_type); 
					if(!stristr($f_type,$tmp_type)){ 
						echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>"; 
						$up_error="yes"; 
					} 

					if(stristr('php,php3,asp,jsp,cgi,aspx,py,pl',$tmp_type)){ 
						echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><script>alert('对不起,不能上传".$tmp_type."格式文件,请将此文件压缩后上传, ".$f_name." 文件上传失败!')</script>"; 
						$up_error="yes"; 
					}

					if (file_exists($uploadfile)&&!$overwrite){ 
						echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>"; 
						$up_error="yes"; 
					}
					$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
					$rand = '';
					for ($x=0;$x<12;$x++){
						$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
					}
					$t=date("ymdHis").substr($gettime[0],2,6).$rand;
		  
					$uploadfile=$attdir.$t.".".$tmp_type; 

					if (round($_FILES[$f_input]['size'][$key]/1024)>$file_size_max) {
						echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_FILES[$f_input]['size'][$key]/1024)."K,大于规定的".$file_size_max."K,上传失败!')</script>"; 
						$up_error="yes";
					}elseif(!move_uploaded_file($_FILES[$f_input]['tmp_name'][$key],MICE_DIR.$uploadfile)){
						echo "<meta http-equiv='Content-Type' content='text/html;charset=utf-8' /><script>alert('对不起,上传文件失败!')</script>"; 
						$up_error="yes"; 
					}
					
					if($up_error!="yes"){
						//上传成功
						$file=new model_File();
						$file->setFilecategoryId($_POST['filecategory_id']);
						$file->setFilename($uploadfile);
						$file->setType('mVedio');
						if($count==1){
							if(MiceFilterHtml($_POST['title'])){
								$file->setTitle(MiceFilterHtml($_POST['title']));
							}else{
								$file->setTitle(MiceFilterHtml(substr($f_name,0,strlen($f_name)-4)));
							}
							$file->setSummary(MiceFilterQuote($_POST['summary']));
							$file->setLink(MiceFilterQuote($_POST['link']));
						}else{
							$file->setTitle(MiceFilterHtml(substr($f_name,0,strlen($f_name)-1-strlen($tmp_type))));
						}
						$file->setCreatedat(time());
						$file->setUserId($miceSession->get('userid'));
						$results=$file->doInsert();

						$_msg1.=$f_name.',';
						$filenames.="<input size='60' type='text' value='".MICE_URL.$uploadfile."' readonly>&nbsp;&nbsp;&nbsp;<span onclick=copyToClipboard('".MICE_URL.$uploadfile."') title='单击复制  ".$f_name."  的地址'>复制URL</span><br>";
					} 
					else{
					$_msg2.=$f_name.',';
					}
				} 
			}

		

		$miceSession = new session();
		$miceSession->set('upfilename', $filenames);
		echo "<script>window.parent.Finish('".urlencode($_msg1)."','".urlencode($_msg2)."');</script>";	
		exit;
	}
}
?>