php jquery 多文件上传简单实例

复制代码 代码如下:
<div id="mulitplefileuploader">Upload</div> 

<div id="status"></div> 
<script> 

$(document).ready(function() 


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

    }, 
    onError: function(files,status,errMsg) 
    {        
        $("#status").html("<font color='red'>Upload is Failed</font>"); 
    } 

$("#mulitplefileuploader").uploadFile(settings); 

}); 
</script> 

upload.php

复制代码 代码如下:
<?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 "<br> 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); 



?> 

php技术php jquery 多文件上传简单实例,转载需保留来源!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。