<?php 
require "../Run.php";
require "../include/class/upload.class.php";
require "../include/class/simage.class.php";
if($login != 1){
	ehtml("请登陆后再上传文件！");
	exit;
}
if($_POST['upload']=='yesyc'){
	echo head('文件上传');
	function mkdirpaths($path){
        $dir = $path;
        //文件创建函数 格式 a/b/c;
        $dirarr = explode("/",$dir);
		$nums = count($dirarr);
		for($i=0;$i<$nums;$i++){
			$dirpath .= $dirarr[$i].'/';
			if(!is_dir($dirpath)){
				mkdir($dirpath); 
				}
			}
		
		}
	$path = 'files/'.$wapid.'/'.$id.'_'.$xid;
	mkdirpaths($path);
	$username = MYID;
	$filetype   =  substr(strrchr($_POST['userfile1'],'.'),1);
	$filename = WAPID.'_'.MD5($_POST['userfile1']).'.'.$filetype;
	$files = file_get_contents($_POST['userfile1']);
	file_put_contents($path.'/'.$filename,$files);
	$filenames[] = $path.'/'.$filename;
	if(is_file($path.'/'.$filename)){
	echo '<div class="tip">远程文件下载成功</div>';
	/* 缩略图 */
	$allowtype = array("png","jpeg","jpg","gif","JPEG","PNG","GIF","JPG");
	$path = 'files_img/'.$wapid.'/'.$id.'_'.$xid;
	$username = MYID;
	$file2 = new file(WAPID,$username,$path,$allowtype,1,'spic');
	$upload2    = $file2->uploadfile();
	foreach ($upload2 as $value2)
	{
	if($value2 =='0'||$value2 =='-1'){
			/*PIC FILED*/
		}else{
			/*缩略图上传成功*/
			$spics[] = $path.'/'.$value2;
		}
	}
		$spic = implode("|",$spics);
		$file = implode("|",$filenames);
		mysql_query('INSERT INTO `download` (`siteid`, `gro`, `title`, `file_path`, `file_ver`, `file_time`, `file_end`, `file_content`, `file_v`, `file_down`, `file_pic`, `file_auter`, `file_lan`, `file_pt`,`shenhe`,`spic`) VALUES (\''.$wapid.'\', \''.$_GET['cid'].'\', \''.$_POST['title'].'\', \''.$file.'\', \''.$_POST['file_ver'].'\', \''.time().'\', \''.$_POST['file_end'].'\', \''.$_POST['file_content'].'\', \'0\', \'0\', \'0\', \''.$id.'\', \''.$_POST['file_lan'].'\', \''.$_POST['file_pt'].'\',\'0\',\''.$spic.'\');');
	}else{
		echo '<div class="tip">远程文件下载失败，文件太大或者宽带资源有限！</div>';
		}
	echo '<div class="mylink"><a href="?cid='.$_GET['cid'].'&">返回上传</a>|<a href="list.php?cid='.$_GET['cid'].'&">文件列表</a></div>';
	echo footer(1);
}else{
//加载文件上传UI视图
require "view/upload.view.php";
}