Simple example of php jquery multiple file upload_PHP tutorial

WBOY
Release: 2016-07-13 17:18:21
Original
768 people have browsed it

Simple example of php jquery multiple file upload_PHP tutorial

复制代码 代码如下:

Upload
 

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

upload.php

复制代码 代码如下:

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

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

    $ret = array(); 

    $error =$_FILES["myfile"]["error"]; 
   { 

        if(!is_array($_FILES["myfile"]['name'])) //single file 
        { 
            $fileName = $_FILES["myfile"]["name"]; 
            move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $_FILES["myfile"]["name"]); 
             //echo "
Error: ".$_FILES["myfile"]["error"]; 

                 $ret[$fileName]= $output_dir.$fileName; 
        } 
        else 
        { 
                $fileCount = count($_FILES["myfile"]['name']); 
              for($i=0; $i < $fileCount; $i++) 
              { 
                $fileName = $_FILES["myfile"]["name"][$i]; 
                 $ret[$fileName]= $output_dir.$fileName; 
                move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName ); 
              } 

        } 
    } 
    echo json_encode($ret); 



?> 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/621674.htmlTechArticle复制代码 代码如下: div id="mulitplefileuploader"Upload/div div id="status"/div script $(document).ready(function() { var settings = { url: "upload.php", method: "POST", all...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!