2012-04-28 2 views
0

나는 ajax 및 php를 통한 파일 업로드에 Ajax Upload을 사용하고 있습니다. /upload URL에서ajaxupload를 사용하여 이미지 업로드

$(document).ready(function() { 
    if ($('#uploadExists').length) { 
     var btnUpload = $('#uploadExists'); 
     var u = new AjaxUpload(btnUpload, { 
      action: '/upload', 
      name: 'fname', 
      onSubmit: function(file, ext){ 
       if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))) { 
         //Bad file                                           
        return false; 
       } 
      }, 
      onComplete: function(file, response){ 
       if (! (/(\.jpg|\.png|\.jpeg|\.gif)/.test(response))) { 
        //Bad file                                            
        console.log(response); 
        return false; 
       } else { 
        console.log(response); 
      } 
     } 
     }); 
    } 
}); 

가 어떻게해야합니까 : 에서 JS 파일이 난 코드의 다음 줄을 썼다? 나는 /0)/ 업로드 (예 : /upload/index.php)에서 $ _POST 변수를 통해 파일을 수신합니다. PHP.

답변

1

파일 이름을 확인하려면 var_dump ($ _ POST)를 시도하십시오. 그런 다음 http://php.net/manual/en/function.move-uploaded-file.php을 사용하여 원하는대로 파일을 이동할 수 있습니다. 이 스크립트는 다중 파일 업로드에서 한 번에 한 파일 씩 전송되므로 표준 HTML 양식을 통해 단일 업로드를 처리하는 것처럼 업로드를 처리합니다.

관련 문제