2014-10-20 3 views
0

나는 약간의 조언을 얻을 수 있는지 궁금합니다.jQuery 업로드 실행 중이지만 파일을 업로드하지 않음

사용자가 동일한 페이지에있는 동안 jquery를 사용하여 파일을 업로드하려고합니다.

저는 무엇이든 시도해 봅니다. 나는 어떤 사람이 외모를 가질 수 있는지, 그리고 어디서 잘못되었는지 말해 줄 수 있는지 궁금해하고있었습니다.

내 HTML은

<form id="import" enctype="multipart/form-data" action="/ajax/postimport" method="POST"> 
    <div class="form-group"> 
     <input type="file" name="filename" id="filename" /> 
    </div> 
    <button type="button" id="importSave">Import</button> 
</form> 

이 Laravel 4

 if (Input::hasFile('filename')) { 
      $file = Input::file('filename'); 
      $destPath = public_path() . '/uploads/'; 
      $filename = str_random(10) . '_' . $file->getClientOriginalName(); 
      $uploadSuccess = $file->move($destPath, $filename); 
     } 

답변

0

단지로 파일을 업로드 할 수 없습니다입니다 다음 내 JQuery와

$("#importSave").click(function() 
{ 
    $.ajax({ 
     url: '/ajax/postimport', 
     type: 'POST', 
     dataType: 'json', 
     contentType: false, 
     processData: false, 
     data: {file: $(#filename).val()}, 
     success: function(data) 
     { 
      alert(data.result) 
     }, 
     error: function(textStatus, errorThrown) 
     { 

     } 
    }); 
}); 

내 PHP입니다 jQuery ajax 함수 사용하기. 이 작업을 수행하려면 FormData 개체를 사용해야합니다. Formdata의 문제점은 not supported in all browsers입니다. 그것을 사용하고 싶다면 this one과 같은 많은 자습서를 언제든지 찾을 수 있습니다.

a jQuery plugin that does the work for you을 사용할 수도 있습니다. :)

0

이렇게 할 수 없습니다. 당신은 단지 하나의 필드 파일 인 $ (# filename) .val()로 포스트 아약스 요청을하고있다.

그래서 ajax 업로드 라이브러리를 사용해야합니다. 몇 가지 대안이 있습니다. 하지만 대부분의

http://www.plupload.com/

http://www.uploadify.com/

처럼
관련 문제