<script type="text/javascript">
function insertRow(){
<span style="white-space:pre"> </span>var rowIndex1 = document.all("addordel").length;
<span style="white-space:pre"> </span>if(rowIndex1 >= 5){
<span style="white-space:pre"> </span>alert('一次最多能上传5个文件');
<span style="white-space:pre"> </span>return false;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>var obj=document.getElementsByName("addordel")[0].cloneNode(true);
<span style="white-space:pre"> </span>document.all("change").appendChild(obj);
}
function delRow(){
<span style="white-space:pre"> </span>var rowIndex = document.all("addordel").length;
<span style="white-space:pre"> </span>if(rowIndex >= 2){
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>event.srcElement.parentNode.removeNode(true); 旧书
document.getElementById("change").removeChild(allrows[allrows.length-1]);
<span style="white-space:pre"> </span>}
}
function chkfile(){
<span style="white-space:pre"> </span>obj = document.getElementsByName('upname[]');
<span style="white-space:pre"> </span>num = obj.length;
<span style="white-space:pre"> </span>for(i=0;i<num;i++){
<span style="white-space:pre"> </span>if(obj[i].value == 0){
<span style="white-space:pre"> </span>alert('请添加上传文件');
<span style="white-space:pre"> </span>return false;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
}
</script>
<div style=" background-image:url(images/upfile.gif); background-position:left; background-repeat:no-repeat; width: 95%; height:43px;"> </div>
<hr style=" width: 95%; border:1px #597ecf solid;" />
<div style=" width: 95%; height:25px; background-color: #FFFFCC; border: 1px #FFFF66; line-height: 25px; text-align:center; color:#ff0000;"> 上传文件限制:100M</div>
<form method="post" enctype="multipart/form-data" action="?act=upfile">
<ul id="change">
<li id="addordel"><input id="upname[]" name="upname[]" type="file" style=" width: 200px; background-color:#f0f0f0; " />
<select id="foundtype[]" name="foundtype[]">
<?php
<span style="white-space:pre"> </span>$typesql = "select genrename from tb_uptype";
<span style="white-space:pre"> </span>$typearr = $conne->getRowsArray($typesql);
<span style="white-space:pre"> </span>$conne->close_rst();
<span style="white-space:pre"> </span>foreach($typearr as $value){
?>
<span style="white-space:pre"> </span><option value="<?php echo $value['genrename']; ?>"><?php echo $value['genrename']; ?></option>
<?php
<span style="white-space:pre"> </span>}
?>
</select>
<select id="ispub[]" name="ispub[]">
<span style="white-space:pre"> </span><option value="0" selected="selected">不公开</option>
<span style="white-space:pre"> </span><option value="1">公开</option>
</select>
<button onClick="delRow()" style=" border: 1px #CCCCCC solid; background-color:#f0f0f0;">删除</button> <button onClick="insertRow()" style=" border: 1px #cccccc solid; background-color: #f0f0f0;">增加</button> </li>
</ul>
<input id="upbtn" name="upbtn" type="submit" value="上传" onClick="return chkfile()" style=" background-color:#f0f0f0; border: 1px #CCCCCC solid;" />
</form>
<?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> 对文件进行下载。</div>';
?>