2011-09-15 4 views
1

Uploadify를 사용하여 CakePHP 앱에서 업로드를 처리하고 있습니다. 일부 업로드가 잘 작동업로드 및 CakePHP - 일부 업로드가 서버에 데이터를 보내지 않습니다.

여기 내 자바 스크립트 코드입니다 :

<script type="text/javascript"> 
$(document).ready(function() { 
    $('.submit input').attr('disabled','disabled'); 
    $('#uploadify').uploadify({ 
    'uploader' : '/uploadify/uploadify.swf', 
    'script' : '/videos/ajaxUpload', 
    'cancelImg' : '/uploadify/cancel.png', 
    'folder' : '/files/video', 
    'auto'  : true, 
    'multi'  : true, 
    'sizLimit' : 31457280, 
    'onComplete': function(event,id,fileObj,response,data){ 
     console.log(fileObj); 
     var responseObj = $.parseJSON(response); 
     console.log(responseObj); 
     $('#upload-complete').html(responseObj.message); 
     $('#VideoName').val(responseObj.name); 
     $('.submit input').attr('disabled',false); 
    }, 
    'buttonText': 'CHOOSE FILE', 
    'fileExt' : '*.mp4;*.mpg;*.mpeg;*.mov;*.avi;*.mpv2;*.qt;*.flv;' 
    }); 
}); 
</script> 

가 그리고 여기에 파일 업로드를 처리하는 컨트롤러 코드입니다 :

public function ajaxUpload(){ 
    $this->autoRender = false; 
    $name = $type = $size = $status = false; 
    $message = 'There was a problem uploading the file'; 
    if (!empty($_FILES)) { 
     if ($_FILES['Filedata']['error'] == 0){ 

      $allowedTypes = array(
       'mp4', 
       'mpg', 
       'mpeg', 
       'mov', 
       'avi', 
       'mpv2', 
       'qt', 
       'flv' 
      ); 
      $fileParts = pathinfo($_FILES['Filedata']['name']); 
      if (in_array($fileParts['extension'],$allowedTypes)){ 
       $tempFile = $_FILES['Filedata']['tmp_name']; 
       $targetPath = WWW_ROOT . $_REQUEST['folder'] . '/'; 
       $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; 
       move_uploaded_file($tempFile,$targetFile); 
       $name = array_pop(explode('/',$targetFile)); 
       $type = $_FILES['Filedata']['type']; 
       $size = $_FILES['Filedata']['size']; 
       $status = 1; 
       $message = 'File successfully uploaded'; 
      }else{ 
       $status = 0; 
       $message = 'Invalid file type.'; 
      } 
     }else{ 
      $status = 0; 
      switch($_FILES['Filedata']['error']){ 
       case 1: 
       $message = 'File exceeded max filesize'; 
       break; 
       case 2: 
       $message = 'File exceeded max filesize'; 
       break; 
       case 3: 
       $message = 'File only partially uploaded'; 
       break; 
       case 4: 
       $message = 'No file was uploaded'; 
       break; 
       case 7: 
       $message = 'There was a problem saving the file'; 
       break; 
       default: 
       $message = 'There was a problem uploading the file'; 
       break; 
      } 
     } 
    }else{ 
     $status = 0; 
     $message = 'No file data received.'; 
    } 
    echo json_encode(
     array(
      'status'=>$status, 
      'name'=>$name, 
      'type'=>$type, 
      'size'=>$size, 
      'message'=>$message 
     ) 
    ); 

}

마법처럼이 모든 작품 그 크기를 넘는 파일의 경우, 컨트롤러는 "No file data received."라고 표시하여 $ _FILES가 비어 있음을 나타냅니다. 이것은 이상합니다. 파일이 php.ini의 일부 지시문을 초과하면 다른 오류 중 하나가 발생할 것으로 예상됩니다.

아무도 도와 줄 수 있습니까?

답변

3

문제는 post_max_size ini 지시어이며, 기본값은 8MB입니다. 업로드 된 파일이이 값을 초과하면 오류가 발생하지 않으며 모든 슈퍼 글로발 (예 : $_FILES$_POST)이 비어 있습니다.

또한 경고를 로그 파일에 인쇄합니다. 그러나 표준 출력에는 아무 것도 없습니다.

post_max_size이 초과되었는지 직접 확인할 수 없습니다. 당신은 당신이 얻은 것과 비교하여 슈퍼 글로블에서 기대했던 것을 기반으로 추측 할 수 있습니다.

한편 upload_max_filesize이 초과되었는지 프로그램 적으로 감지하려면 $_FILES['userfile']['error']에 오류가 있는지 확인하십시오.

+0

안녕하세요 Ben, 답변 주셔서 감사합니다.하지만이 경우 $ _FILES는 비어 있지 않으므로 서버에서 "No file data received"를 반환하지 않고 "File exceeded max filesize"를 반환합니다. – Will

+1

4.2 미만의 PHP 버전을 사용하고 있습니까? 4.2 이전에 post_max_size를 초과하면 $ _FILES는 완전히 비어 있고 오류 메시지가 포함되지 않습니다. –

+0

그리고 "약 8MB"가 문제가 발생한 곳이기 때문에 증상은 완전히 post_max_size와 일치합니다. 나는 그것이 그 문제가 무엇인지 확신한다. –

관련 문제