Home > Backend Development > PHP Tutorial > php jquery multiple file upload_PHP tutorial

php jquery multiple file upload_PHP tutorial

WBOY
Release: 2016-07-13 17:18:48
Original
1142 people have browsed it

php jquery 多文件上传

php jquery 多文件上传演示

XML/HTML Code
  1. Upload
  2. <script> </li> <li class="alt"> </li> <li>$(document).ready(function() </li> <li class="alt">{ </li> <li> </li> <li class="alt">var settings = { </li> <li> url: "upload.php", </li> <li class="alt"> method: "POST", </li> <li> allowedTypes:"jpg,png,gif,doc,pdf,zip", </li> <li class="alt"> fileName: "myfile", </li> <li> multiple: true, </li> <li class="alt"> onSuccess:function(files,data,xhr) </li> <li> { </li> <li class="alt"> $("#status").html("<font color="green">Upload is success</font>"); </li> <li> </li> <li class="alt"> }, </li> <li> onError: function(files,status,errMsg) </li> <li class="alt"> { </li> <li> $("#status").html("<font color="red">Upload is Failed</font>"); </li> <li class="alt"> } </li> <li>} </li> <li class="alt">$("#mulitplefileuploader").uploadFile(settings); </li> <li> </li> <li class="alt">}); </li> <li></script>

    upload.php

    PHP Code
    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 {
    19. $fileName = $_FILES["myfile"]["name"][$i];
    20. $ret[$fileName]= $output_dir.$fileName;
    21. move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName );
    22. }
    23. }
    24. }
    25. echo json_encode($ret);
    26. }
    27. ?>


      原文地址:http://www.freejs.net/article_biaodan_116.html

      www.bkjia.comtruehttp://www.bkjia.com/PHPjc/621610.htmlTechArticlephp jquery 多文件上传 演示 XML/HTML Code Upload script $(document).ready(function() { var settings = { url: "upload.php", method: "POST", allowedTypes:"jpg,png,gif,doc,pdf,z...
Related labels:
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