Heim  >  Artikel  >  Backend-Entwicklung  >  php jquery 多文件上传简单实例_PHP

php jquery 多文件上传简单实例_PHP

WBOY
WBOYOriginal
2016-06-01 11:57:571047Durchsuche

jQuery

php jquery 多文件上传简单实例_PHP

复制代码 代码如下:

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"); <br><br> }, <BR> onError: function(files,status,errMsg) <BR> { <BR> $("#status").html("<font color='red'>Upload is Failed"); <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               { 
                $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); 



?> 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn