2016-08-06 8 views
0

이제 파일 업로드 작업을하고 있습니다. 그래서 아약스 호출을 사용하여 코드 조각을 작성했습니다. 내 로컬 서버에서 파일 (GB)을 업로드 할 때이 작업이 완벽하게 작동합니다.대용량 파일 업로드 ajax 호출을 통해 실패했습니다.

$.ajax({ 
    type: "POST", 
    url: "process/uploadFlatFile.htm", 
    enctype : 'multipart/form-data', 
    //timeout: 0, 
    crossDomain: true, 
    data : formData, 
    processData: false, 
    contentType: false, 
    cache: false, 
    dataType: 'json', 
    xhr: function() { 
     myXhr = $.ajaxSettings.xhr(); 
     //myXhr = new XMLHttpRequest(); 
     console.log("myXhr: " + myXhr.upload); 
     if(myXhr.upload){ 
      console.log("adding progress event listener"); 
      myXhr.upload.addEventListener('progress', showProgress, false); 
     } else { 
      console.log("Upload progress is not supported."); 
     } 
     return myXhr; 
    },beforeSend: function(xhr, opts) { 
     console.log("beforeSend:xhr: " + xhr + ", opts: " + opts); 
     currXhr = xhr; 
     showProgressBar(); 
     status.empty(); 
     var percentVal = '0%'; 
     bar.width(percentVal); 
     percent.html(percentVal); 
     $(cancelSelector).removeAttr('disabled'); 
    }, 

    success: function(result,status,xhr) { 
     console.log("success:result: " + result); 
     console.log("success:status: " + status); 
     console.log("success:xhr: " + xhr); 
     var percentVal = '100%'; 
     bar.width(percentVal); 
     //$("#fountainGG").hide(); 
     percent.html(percentVal); 
     $.unblockUI({ 
      onUnblock: function(){ 
       if(result=="success"){ 
        console.log("SUCCESS PART :") 

        alertMessage("Success","File Uploaded Successfully","info"); 
        setTimeout(function(){ 
         window.location.href = "processFlow.htm"; 
         //newProcessClicked('yes'); closeConDiv() 
        }, 2000); 
       }else{ 

        alertMessage("Error","Error in upload. Try Again !","info"); 
       } 
      } 
     }); 
    }, 
    complete: function(xhr,status){ 
     console.log("COMPLETE PART :") 
     console.log("complete:status: " + status + ", xhr: " + xhr); 
     $('#btnGoUpload').prop('disabled', false); 
    }, 
    error: function(xhr, statusText, err) { 
     $.unblockUI(); 
     console.log("statusText: " +statusText); 
     console.log("error: " + err); 
     var msg = "Error in uploading file. Try Again !"; 
     if (err == "abort"){ 
      msg = "File upload aborted."; 
     } 
     alertMessage("Error",msg,"info"); 
    } 
}); 

하지만 공용 서버에서 파일 (30 기가 이상) GB를 업로드하고 때 시간이 몇 후 아약스 호출의 일부 에러거야. 연결 시간 제한 문제라고 생각합니까? 연결 시간 제한 문제가 있다면 어떻게 해결할 수 있습니까?

ini_set('max_execution_time', 0); 

는 당신이 필요로하는, 그 또한 당신을 차단할 수 있습니다, 최대 업로드 크기를 늘리려면 :

+0

'아약스 호출 중 오류 부분'으로 이동하면 어떤 오류가 기록됩니까? 즉, statusText와 err은 무엇입니까 –

+0

statusText에 '오류'가 표시됩니다. – user3159781

+0

오류 란 무엇입니까? –

답변

0

이 명령에 제한을 가능한 시간을 해결할 수 있습니다, 당신의 PHP 수신기 스크립트의 시작에 넣어합니다

; Maximum allowed size for uploaded files. 
upload_max_filesize = 40M 

; Must be greater than or equal to upload_max_filesize 
post_max_size = 40M 

편집하고 웹 서버를 다시 시작 php.ini 파일에이 upload_max_filesize와 post_max_size을의 값을 설정합니다.

+0

이것은 PHP가 아닙니다. 이것은 자바 스크립트 코드 – user3159781

+0

입니다. "process/uploadFlatFile.htm"에서 html로 업로드 된 파일을 처리하는 것이 가능하다는 것을조차 알지 못했습니다. 어쨌든, 수신 서버의 설정 파일을보십시오. – technico

+0

서버가 무엇입니까? – technico