php jquery 多文件上传

本文展示了如何使用PHP和jQuery实现多文件上传功能,包括上传文件的限制设置、错误处理以及成功上传后的状态反馈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

php jquery 多文件上传

php jquery 多文件上传

 

XML/HTML Code
  1. <div id="mulitplefileuploader">Upload</div>  
  2.   
  3. <div id="status"></div>  
  4. <script>  
  5.   
  6. $(document).ready(function()  
  7. {  
  8.   
  9. var settings = {  
  10.     url: "upload.php",  
  11.     method: "POST",  
  12.     allowedTypes:"jpg,png,gif,doc,pdf,zip",  
  13.     fileName: "myfile",  
  14.     multiple: true,  
  15.     onSuccess:function(files,data,xhr)  
  16.     {  
  17.         $("#status").html("<font color='green'>Upload is success</font>");  
  18.           
  19.     },  
  20.     onError: function(files,status,errMsg)  
  21.     {         
  22.         $("#status").html("<font color='red'>Upload is Failed</font>");  
  23.     }  
  24. }  
  25. $("#mulitplefileuploader").uploadFile(settings);  
  26.   
  27. });  
  28. </script>  

upload.php

PHP Code
  1. <?php  
  2. //If directory doesnot exists create it.  
  3. $output_dir = "../upload";  
  4.   
  5. if(isset($_FILES["myfile"]))  
  6. {  
  7.     $ret = array();  
  8.   
  9.     $error =$_FILES["myfile"]["error"];  
  10.    {  
  11.       
  12.         if(!is_array($_FILES["myfile"]['name'])) //single file  
  13.         {  
  14.             $fileName = $_FILES["myfile"]["name"];  
  15.             move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir$_FILES["myfile"]["name"]);  
  16.              //echo "<br> Error: ".$_FILES["myfile"]["error"];  
  17.                
  18.                  $ret[$fileName]= $output_dir.$fileName;  
  19.         }  
  20.         else  
  21.         {  
  22.                 $fileCount = count($_FILES["myfile"]['name']);  
  23.               for($i=0; $i < $fileCount$i++)  
  24.               {  
  25.                 $fileName = $_FILES["myfile"]["name"][$i];  
  26.                  $ret[$fileName]= $output_dir.$fileName;  
  27.                 move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName );  
  28.               }  
  29.           
  30.         }  
  31.     }  
  32.     echo json_encode($ret);  
  33.    
  34. }  
  35.   
  36. ?>  

 


原文地址: http://www.freejs.net/article_biaodan_116.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值