2012-04-20 7 views
0

웹 페이지를 변경하지 않고 서버에 단일 파일을 보내려고했습니다. ... 웹 페이지를 변경하지 않고 http://cmlenz.github.com/jquery-iframe-transport/ 내가 업로드 진행 방법에 대한 매우 혼란 스러워요 uploadimg.php 반환 :ajax를 사용하여 파일을 업로드하는 방법

<br /> 
<b>Notice</b>: Undefined index: photo in <b>C:\website\uploadimg.php</b> on line <b>2</b><br /> 
<br /> 
<b>Notice</b>: Undefined index: photo in <b>C:\website\uploadimg.php</b> on line <b>3</b><br /> 
<img src="userimg/" /> 

내 파일 :

postAd을 나는이 플러그인을 사용하기로 결정했다. PHP

<html> 
<head> 
<script src="jquery.js"></script> 
<script src="jquery-iframe-transport.js"></script> 
<script> 
$(document).ready(function(){ 
    $('#photo1').on('change', function(){ 
     $.ajax({ 
      url: "uploadimg.php", 
      files: $("#photo1:file"), 
      iframe: true, 
      processData: false 
     }).done(function(data){ 
      console.log(data); 
     }); 
    }); 
}); 
</script> 
</head> 
<body> 
<input type='file' name='photo' id='photo1' /></br> 
</body> 
</html> 

uploadimg.php

<?php 
$file_tmp = $_FILES['photo']['tmp_name'][0]; 
$file = $_FILES['photo']['name'][0]; 
move_uploaded_file($file_tmp, "userimg/$file"); 
echo '<img src="userimg/' .$file .'" />'; 
?> 

답변

0

양식을 제출하지 않으므로 '사진'필드는 AJAX 호출과 함께 전송되지 않습니다. 디버거를 사용할 수있는 경우 $ _FILES 배열을 검사하여 채워진 항목을 확인합니다. this에서 'userfile'색인을 찾고있는 것으로 보입니다. 그러나 확실하지 않습니다.

0
function upload(event) { 

var formData = new FormData($('#uploadForm')[0]); 

$.ajax({    
    url  : "upload.do", 
    type  : "POST", 
    data : formData, 
    cache : false, 
    contentType  : false, 
    processData : false, 

}); 

@RequestMapping(value = "/uploadCsr", method = RequestMethod.POST) 
    @ResponseBody 
    public String uploadCsr(@RequestParam("fileUpload") MultipartFile file, HttpServletResponse response) { 
// read the file using inputstream 

} 
관련 문제