当前位置: 绿色php资源 > php典型模块 >

php批量上传支持图片和文件

php批量上传内容简介

软件类型:国产软件    授权方式:共享软件
界面语言:简体中文    软件大小:未知
文件类型:.exe      发布时间:2009-09-14

此文档为swfuplaod上传例子. 可以上传单文件多文件.迅雷下载源码。已经测试无错误!

部分代码

 

  1. <?php  
  2.     // Work-around for setting up a session because Flash Player doesn't send the cookies  
  3. /*  if (isset($_POST["PHPSESSID"])) {  
  4.         session_id($_POST["PHPSESSID"]);  
  5.     }  
  6.     session_start();  
  7.  
  8.     if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {  
  9.         echo "There was a problem with the upload";  
  10.         exit(0);  
  11.     } else {  
  12.         echo "Flash requires that we output something or it won't fire the uploadSuccess event";  
  13.     }  
  14.       
  15. */ 
  16. $updir="./upload/";//上传目录  
  17. $dirtype="1";//目录保存方式1:年/月/日;2:年/月;默认:年  
  18. $renamed="1";//是否重命名1表示重命名0表示用原来的文件名  
  19. $overwrite="1";//是否覆盖1表示覆盖0表示不覆盖  
  20. if (isset($_FILES["Filedata"]) && is_uploaded_file($_FILES["Filedata"]["tmp_name"]) && $_FILES["Filedata"]["error"] == 0) {  
  21.     //上传文件赋值给$upload_file  
  22.     $upload_file=$_FILES["Filedata"];  
  23.     //获取文件类型  
  24.     $file_info=pathinfo($upload_file["name"]);  
  25.     //获取文件扩展名  
  26.     $file_ext=$file_info["extension"];  
  27.     //设置路径方式  
  28.     switch($dirtype){  
  29.         case '1':  
  30.             $m_dir=date(Y)."/".date(m)."/".date(d)."/";  
  31.             break;  
  32.         case '2':  
  33.             $m_dir=date(Y)."/".date(m)."/";  
  34.             break;  
  35.         default:  
  36.             $m_dir=date(Y)."/";  
  37.             break;  
  38.     }  
  39.     //设置上传的路径  
  40.     $upload_path=$updir.$m_dir;  
  41.     //建立文件夹  
  42.     create($upload_path);  
  43.     //需要重命名的  
  44.     if($renamed){  
  45.         list($usec$sec) = explode(" ",microtime());  
  46.         $upload_file['name']=substr($usec,2).'.'.$file_ext;  
  47.         unset($usec);  
  48.         unset($sec);  
  49.     }  
  50.     //设置默认服务端文件名  
  51.     $upload_file['filename']=$upload_path.$upload_file['name'];  
  52.     //检查文件是否存在  
  53.     if(file_exists($upload_file['filename'])){  
  54.         if($overwrite){  
  55.             @unlink($upload_file['filename']);  
  56.         }else{  
  57.             $j=0;  
  58.             do{  
  59.                 $j++;  
  60.                 $temp_file=str_replace('.'.$file_ext,'('.$j.').'.$file_ext,$upload_file['filename']);  
  61.             }while (file_exists($temp_file));  
  62.             $upload_file['filename']=$temp_file;  
  63.             unset($temp_file);  
  64.             unset($j);  
  65.         }  
  66.     }  
  67.     if(@move_uploaded_file($upload_file["tmp_name"],$upload_file["filename"])){  
  68.         //下面插入一段把路径保存到数据库中的代码;  
  69.         // Create a pretend file id, this might have come from a database.  
  70.         //产生一个上传文件id,这可能来自数据库;  
  71.         //这里必需echo内容可以是文件id或许数据库中的id,不然程序会出现错误,没有内容传回到index.php表单中的hidFileID中  
  72.         echo $upload_file["filename"];  
  73.     }else{  
  74.         echo '';  
  75.     }  
  76. else {  
  77.     echo ' '// I have to return something or SWFUpload won't fire uploadSuccess  
  78. }  
  79. //建立文件夹  
  80. function create($dir)  
  81. {  
  82.     if (!is_dir($dir))  
  83.     {  
  84.         $temp = explode('/',$dir);  
  85.         $cur_dir = '';  
  86.         for($i=0;$i<count($temp);$i++)  
  87.         {  
  88.             $cur_dir .= $temp[$i].'/';  
  89.             if (!is_dir($cur_dir))  
  90.             {  
  91.                 @mkdir($cur_dir,0777);  
  92.                 @fopen("$cur_dir/index.htm","a");  
  93.             }  
  94.         }  
  95.     }  
  96. }  
  97.       
  98. ?> 

完整案例在附件:请下载

温馨提示:
①:如果您发现有php批量上传支持图片和文件免费下载,而绿色php资源未能索引到,请及时通知我们。您的热心是对绿色php资源网最大的支持。
②:php批量上传支持图片和文件是优秀的免费的资源,索引php批量上传支持图片和文件链接到本站只是为了让您方便下载。支持作者请购买正版。
③:本网站是一个免费绿色php资源下载站,仅提供php批量上传支持图片和文件资源免费下载,若有下载php批量上传支持图片和文件资源者请24小时后自行删除。
④:如果作品浏览,或对php批量上传支持图片和文件作品内容、版权等方面有质疑,或对绿色php资源网有意见建议请及时反馈给我们,以便我们及时处理!

下载地址
标签(Tag):上传 批量上传 swfuplaod上传 php批量上传
------分隔线----------------------------
热门软件