无为清净楼资源网 Design By www.qnjia.com

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,jquery

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com