|
发表于 2005-11-24 16:22:28
|
显示全部楼层
晕,看的晕死了,这个是我写的一个单个文件上传的代码,多个加个循环应该就可以了吧,不过是php的
asp的上传木自己写过
:?
- //图片上传信息开始
- //设置上传文件类型
- $filetypes = array('gif','jpg','jpeg','png','bmp');
- //设置上传文件大小
- $maxsize = 512000;
- //文件上传目录
- $destdir=date("Y_m");
- $dest_dir1="../uploadfile";
- $dest_dir2="../uploadfile/image";
- $dest_dir3="../uploadfile/image/".$destdir;
- $dest_dir4="/uploadfile/image/".$destdir;
- //读取上传文件信息
- $file_file = $HTTP_POST_FILES['up_file'];
- $file_name = $HTTP_POST_FILES['up_file']['name'];
- $file_type = $HTTP_POST_FILES['up_file']['type'];
- $file_size =$HTTP_POST_FILES['up_file']['size'];
- //判断是否填写上传信息
- if ($file_name!=""){
- //获得文件类别信息
- $ftype = explode("/", $file_type);
- while (list($key,$value) = each($ftype)) {
- $fty[$key]=$value;
- }
- //获取文件扩展名
- $fkzn = explode(".", $file_name);
- while (list($key,$value) = each($fkzn)) {
- $fkzna[$key]=$value;
- }
- //设置上传后得到的文件名
- $nfile_name=date("Ymdhis")."_".$file_size.".".$fkzna[1];
- //设置文件上传后的位置
- $dest=$dest_dir4.'/'.$nfile_name;
- $dest1=$dest_dir3.'/'.$nfile_name;
- if ($fty[0]=="image"){
- //判断是否为要求上传文件类型
- if (in_array($fkzna[1], $filetypes)){
- //判断文件是否超出大小
- if ($file_size>$maxsize){
- echo"<script>alert('对不起,上传文件超出了500K,请返回!');history.go(-1);</script>";
- }else{
- //判断文件上传目录是否存在,不存在新建
- if (is_dir($dest_dir1)){
- $fdir=1;
- }else{
- $fdir=0;
- }
- if ($fdir==0){
- mkdir($dest_dir1, 0700);
- }
- if (is_dir($dest_dir2)){
- $fdir2=1;
- }else{
- $fdir2=0;
- }
- if ($fdir2==0){
- mkdir($dest_dir2, 0700);
- }
- if (is_dir($dest_dir3)){
- $fdir3=1;
- }else{
- $fdir3=0;
- }
- if ($fdir3==0){
- mkdir($dest_dir3, 0700);
- }
- //上传文件
- $r=move_uploaded_file($file_file['tmp_name'],$dest1);
- $images=$dest;
- }
- }else{
- echo"<script>alert('对不起,不能传此类型的文件!');history.go(-1);</script>";
- }
- }else{
- echo"<script>alert('对不起,上传文件必须为图片文件,请返回!');history.go(-1);</script>";
- }
- }else{
- $images="";
- }
- //图片上传信息结束
复制代码 |
|