2017-02-28 7 views
0

지난 며칠 동안 ajaxForm 플러그인을 사용하여 여러 파일을 업로드하는 방법을 생각해 보지 않았습니다. 비록 내가 전체에 대한 몇 가지 예를 찾았음에도 불구하고 그들은별로 도움이되지 않거나 내가 hava가 그와 같이 작동하도록 관리하는 하나의 파일 업로드를 보여주고 있지만 여러 파일을 가지고있는 것은 아닙니다. 그 모든입니다 내 생각여러 파일 업로드가 포함 된 ajaxForm 제출

if(isset($_FILES["FileInput"])){ 
    $UploadDirectory = $base_url . '/subSystems/drivers/driverLoads/fetchDrivers/personnelUploads/'; 

for($i = 0; $i < count($_FILES["FileInput"]['name']);$i++){ 
//check if this is an ajax request 
    if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){ 
     die(); 
    } 


//Is file size is less than allowed size. 
    if($_FILES["FileInput"]["size"][$i] > 5242880) { 
    die("File size is too big!"); 
    } 

//allowed file type Server side check 
switch(strtolower($_FILES['FileInput']['type'][$i])) 
    { 
     //allowed file types 

     //disabled till further notice 
     case 'image/png': 
     case 'image/gif': 
     case 'image/jpeg': 
     case 'image/pjpeg': 
     case 'text/plain': 
     case 'text/html': //html file 

     case 'application/x-zip-compressed': 
     case 'application/pdf': 
     case 'application/msword': 
     case 'application/vnd.ms-excel': 
     case 'video/mp4': 
      break; 
     default: 
      die('Unsupported File!'); //output error 
} 

    if(move_uploaded_file($_FILES['FileInput']['tmp_name'][$i], $UploadDirectory.$_FILES['FileInput']['name'][$i])){ 
     die('Success! File Uploaded.'); 
    }else{ 
     die('Error uploading File!'); 
    } 

    } 

}else{ 
    $error = codeToMessage($_FILES["FileInput"]["error"][$i]); 
    die('Something wrong with upload! Is "upload_max_filesize" set correctly?' . $error); 
} 

:

$(document).ready(function() { 
$('#submit-btn').click(function(e) { 
     e.preventDefault(); 
     $('#uploadForm').ajaxForm({ 
      target: '#output', // target element(s) to be updated with server response 
      beforeSubmit: beforeSubmit, // before submission callback function 
      success:  afterSuccess, // after submission callback 
      uploadProgress: OnProgress, //check on the upload progress 
      resetForm: true,  // reset the form if upload is success 
      data:{driverid:driverid} //send the driverid as well 
     }).submit();    
    }); 

및 PHP 코드 : 여기

는 HTML 코드

<div id="upload-wrapper"> 
<div align="center"> 
<form action="driverLoads/fetchDrivers/personnelUploads/processupload.php" method="post" enctype="multipart/form-data" id="uploadForm"> 
    <input name="FileInput[]" id="FileInput" type="file" multiple/> 
    <input type="submit" id="submit-btn" value="Upload" /> 
    <img src="driverLoads/fetchDrivers/personnelUploads/images/ajax-loader.gif" id="loading-img" style="display:none;" alt="Please Wait"/> 
</form> 
<div id="progressbox" ><div id="progressbar"></div ><div id="statustxt">0%</div></div> 
<div id="output"></div> 

와 자바 스크립트 코드 the r 이해해야 할 질문을위한 elevant 코드. 다시 한 파일을 업로드 할 때 코드가 제대로 작동합니다. 이 코드는 또한 업로드 할 경우 잘 작동합니다. 그러나 3 번째 파일을 위해 arguement를 사용한다고 가정 해 봅시다. 첫 번째 파일 만 업로드 할 것입니다.이 오류에 대해 더 많은 경험이 있으면 도움을 청하십시오.

미리 감사드립니다.

다음
if(move_uploaded_file($_FILES['FileInput']['tmp_name'][$i], $UploadDirectory.$_FILES['FileInput']['name'][$i])){ 
     die('Success! File Uploaded.'); 

라인 제거하려고 :

die('Success! File Uploaded.'); 

를 (또는 주석!)

그것은 작동합니까 말한다 라인에 PHP 코드에서

답변

1

?