Home > Backend Development > PHP Tutorial > PHP jquery multiple file upload implementation code

PHP jquery multiple file upload implementation code

WBOY
Release: 2016-07-25 08:55:27
Original
825 people have browsed it
  1. Upload
  2. <script> </li> <li>$(document).ready(function() </li> <li>{</li> <li>var settings = { </li> <li> url: "upload.php", </li> <li> method: "POST", </li> <li> allowedTypes:"jpg,png,gif,doc,pdf,zip", </li> <li> fileName: "myfile", </li> <li> multiple: true, </li> <li> onSuccess:function(files,data,xhr) </li> <li> { </li> <li> $("#status").html("<font color='green'>Upload is success</font>"); </p></li> <li><p> }, </li> <li> onError: function(files,status,errMsg) </li> <li> { </li> <li> $("#status").html("<font color='red'>Upload is Failed</font>"); </li> <li> } </li> <li>} </li> <li>$("#mulitplefileuploader").uploadFile(settings); </p></li> <li><p>}); </li> <li></script>

复制代码

2,php多文件上传代码 upload.php

  1. //If directory doesnot exists create it.
  2. $output_dir = "../upload";

  3. if(isset($_FILES["myfile"]))

  4. {
  5. $ret = array();
  6. $error =$_FILES["myfile"]["error"];
  7. {
  8. if(!is_array($_FILES["myfile"]['name'])) //single file
  9. {
  10. $fileName = $_FILES["myfile"]["name"];
  11. move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $_FILES["myfile"]["name"]);
  12. //echo "
    Error: ".$_FILES["myfile"]["error"];
  13. $ret[$fileName]= $output_dir.$fileName;
  14. }
  15. else
  16. {
  17. $fileCount = count($_FILES["myfile"]['name']);
  18. for($i=0; $i < $fileCount; $i++)
  19. {
  20. $fileName = $_FILES["myfile"]["name"][$i];
  21. $ret[$fileName]= $output_dir.$fileName;
  22. move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName );
  23. }
  24. }
  25. }
  26. echo json_encode($ret);
  27. }
  28. ?>

复制代码

3,效果图,如下: PHP jquery多文件上传

>>> 您可能感兴趣的文章: PHP图片上传类(多文件上传、缩略图、水印) PHP上传多文件、多图片的示例代码 php上传多文件与多图片的实例代码 php多文件上传的简单示例分析 php 普通表单多文件上传的例子 php 多文件上传的简单例子(入门) php多文件上传的三种方法



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template