测试十图上传,不会出现重复文件!
admin_pic_upload.php 文件
<?php
include_once('admin_global.php');
if($_GET["AdminPurview"]!=""){
$db->Get_user_checkadmin($_COOKIE["AdminName"], $_COOKIE["password"], $_COOKIE["RndPassword"],$_GET["AdminPurview"]);
$Result = Trim($_GET["Result"]);
}
else{
echo "你没有处理该操作的权限";
exit();
}
if($_POST['upload_submit']){
$pic_upload=$_POST['pic_upload'];
$pic_alt=$_POST['pic_alt'];
$pic_thumb=$_POST['pic_thumb'];
$thumb_width=$_POST['thumb_width'];
$thumb_height=$_POST['thumb_height'];
foreach($_FILES['pic_upload']['tmp_name'] as $key=>$value){
if(empty($value)){continue;}
$value_arr=array('');
$pic_info=array('');
//有图则上传图片
if(is_uploaded_file($value)){
$pic_thumb=intval($pic_thumb[$key]);
$thumb_width=empty($thumb_width[$key])?$_sys['thump_width']:intval($thumb_width[$key]);
$thumb_height=empty($thumb_height[$key])?$_sys['thump_height']:intval($thumb_height[$key]);
$pic_info['tmp_name']=$value;
$pic_info['size']=$_FILES['pic_upload']['size'][$key];
$pic_info['type']=$_FILES['pic_upload']['type'][$key];
$pic_info['name']=$_FILES['pic_upload']['name'][$key];
//调用图片上传函数
$value_arr=upload_pic($pic_info,array('image/gif','image/jpeg','image/png','image/jpg','image/bmp','image/pjpeg'),'upload',1024,$pic_thumb,$thumb_width,$thumb_height,0,1);
//入库
$pic_name=$value_arr['pic_name'];//图片名称空
$pic_ext=$value_arr['pic_ext'];//图片扩展名
$pic_title = $pic_alt[$k];//图片描述
$pic_size = $value_arr['pic_size'];//图片大小
$pic_dir = $value_arr['pic_dir'];//上传路径
$pic_time = $value_arr['pic_time'];//上传时间
$pic_thumb = $value_arr['thumb'];//缩略图
$sql="INSERT INTO `sy919_uploadpic`(pic_name,pic_ext,pic_alt,pic_size,pic_dir,pic_thumb,pic_time) VALUES ('".$pic_name."','".$pic_ext."','".$pic_alt."','".$pic_size."','".$pic_dir."','".$pic_thumb."','".$pic_time."')";
mysql_query($sql);
}
}
}
?>
页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="images/admin_right.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div class="total">
<form name="upload_from" id="upload_from" action="" method="post" enctype="multipart/form-data">
<table class="tableClass" width="95%" border="0" align="center" cellpadding="5" cellspacing="1" >
<tr>
<th height="22" colspan="2">【图片上传】</th>
</tr>
<tr>
<td width="25%" align="right">多图上传:</td>
<td width="75%"><input name="upload_num" value="1" id="upload_num" style="width:30px;padding:2px 0;" /> <input type="submit" id="add_num" value="增加" />(允许上传的图片类型:)</td>
</tr>
<?php
$upload_num=$_POST["upload_num"]?$_POST["upload_num"]:1;
for($i=0;$i<$upload_num;$i++){
?>
<tr>
<td width="25%" align="right">图片上传:</td>
<td width="75%">
<input type="file" name="pic_upload[]" />
图片说明(alt):<input type="text" name="pic_alt[]" />
缩略图:<input type="checkbox" value="1" name="pic_thumb[]" style="margin:0 5px;" />
宽:<input name="thumb_width[]" id="thumb_width" value="" style="margin:0 5px; width:40px;" />px
高:<input name="thumb_height[]" id="thumb_height" style="margin:0 5px; width:40px;" value="" />px</td>
</tr>
<?php }?>
<tr>
<td width="25%" align="right"></td>
<td width="75%"><input type="submit" value="上传" name="upload_submit" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
upload_pic函数
function upload_pic($pic_info,$pic_typelimt,$upload_path='upload/img/',$pic_maxsize=1024,$pic_thumb=0,$thumb_width='100',$thumb_height='100',$watermark=0,$watertype=1){
if(is_uploaded_file($pic_info['tmp_name'])){
$oldpic_info=pathinfo($pic_info['name']);//原始图片名称
$pic_type=$pic_info['type']; //图片类型
if(!is_dir($upload_path)){
show_msg('目录不存在','',10);
exit();
}
$pic_dir="upload/img/".date('Ymd').'/'; //建立保存图片路径
if(!is_dir($pic_dir)){
mkdir($pic_dir);
}
$_num=1;
while(is_file($pic_dir.date('YmdHis').'_'.$_num.'.'.$oldpic_info['extension'])){
$_num+=1;
}
$pic_name=date('YmdHis').'_'.$_num;
$pic_path=$pic_dir.$pic_name.'.'.$oldpic_info['extension'];
$return_name['pic_name']=$pic_name;//上传图片名
$return_name['pic_ext']=$oldpic_info['extension'];//上传文件扩展名
$return_name['pic_size']=$pic_info['size'];//上传图片大小
$return_name['pic_dir']=$pic_dir;//上传图片路径
$return_name['pic_time']=mktime();//上传时间
//开始上传
if(!move_uploaded_file($pic_info['tmp_name'],$pic_path)){
show_msg('图片上传失败','',3);
}
return $return_name;
}
}