<?php
	include_once 'conn/conn.php';
	$filename = $_FILES['upname']['name'];			//读取上传文件名，并存为数组
	$filetype = $_POST['foundtype'];				//读取上传文件的类别
	$tmpname = $_FILES['upname']['tmp_name'];		//读取临时文件名，并存为数组
	$tmpsize = $_FILES['upname']['size'];			//上传文件大小
	$tmppub = $_POST['ispub'];						//是否公开
	$file_path = 'upfile/';
	$max = 0;
	if(!is_null($tmpsize)){
		foreach($tmpsize as $value){
			$max += $value;
		}
		if($max > 100000000 or $max <= 0){
			echo '<script>alert("上传文件总大小大于100M，请重新选择1");location="'.$_SERVER['HTTP_REFERER'].'";</script>';
		}
	}else{
		/*var_dump($tmpsize);
		exit();*/
		echo '<script>alert("上传文件错误，请重新检查程序");location="'.$_SERVER['HTTP_REFERER'].'";</script>';
	}
	$chkdownnum = '';
	for($i = 0; $i < 15; $i++){
		$chkdownnum .= dechex(rand(0,15));
	}
	for ($i = 0; $i < count($filename); $i++){		//通过循环将多个文件全部上传
		move_uploaded_file($tmpname[$i],$file_path.$filename[$i]);
		//添加数据库
		$insertsql = 'insert into tb_upfile (filename,filepath,filetype,upauthor,chkdownnum,ispub) values("'.trim($filename[$i]).'","'.$file_path.$filename[$i].'","'.$filetype[$i].'","'.$_SESSION['name'].'","'.trim($chkdownnum).'",'.$tmppub[$i].')';
		$conne->uidRst($insertsql);
	}
	echo '<div style=" padding-top: 30px;">文件上传成功，可以通过下载码：<font color="#FF0000">'.$chkdownnum.'</font>&nbsp;对文件进行下载。</div>';
?>