2013-01-07 5 views
0

formData를 사용하여 이메일()에 첨부 : 나는 제목 아래에서 here의 코드를 사용하고
submit success but upload not work at combine form은 파일을 업로드하고 가능한 중복

는 "만 제출 파일". 코드는 정말 간단하고 작지만 console.log에 "file", 위치가 없으면 webkitrelativepath는 ""입니다. 제출시 파일 이름, 크기 등을 볼 수 있습니다. 나는 그것을 내 feedback.php 파일에 게시하고 거기에서 전자 메일에 첨부해야하지만 formData에서 파일을 가져 와서 내 업로드 폴더를 업로드하는 방법을 모르므로 전자 메일을 보낼 수 있습니다. -mail it ...

감사합니다.

편집 :

내가 지금 사용하고 무엇 코드 :

var fileInput = document.getElementById('file-upload-field'); 
var file = fileInput.files[0]; 
var formData = new FormData(); 
formData.append('file', file); 
console.log(file); 

$.ajax({ 
    url: baseUrl + "feedback.php", 
    data: file, 
    cache: false, 
    contentType: false, 
    processData: false, 
    type: 'POST', 
    success: function(file){ 
    alert(file); 
    } 
}); 

내 feedback.php에

foreach($_FILES as $file){ 
    $target_path = "uploads/"; 
    $target_path = $target_path .basename($file['name']); 



if(move_uploaded_file($file['tmp_name'], $target_path)) { 
echo "the file ".basename($file['name'])." has been uploaded"; 
} 
else { 
echo "there was an error"; 
} 
$mail->AddAttachment($target_path); 

}

이 업로드되지 않거나 어디서나 파일을 첨부하십시오 ...

+0

: HTTP : //blog.new-bamboo .co.uk/2012/01/10/우스꽝스럽게 단순한 아약스 업로드와 함께 formdata? –

+0

알았어, 내 의견을 바꿨다. 초. File API를 명시 적으로 사용하고 있다는 사실을 알지 못했습니다. – Charles

+0

이렇게 업로드 된 파일은'$ _FILES' *에 나타나지 않습니다. 정의 된 경우'stdin'을 읽거나'$ HTTP_RAW_POST_DATA'를 볼 필요가 있습니다. 즉, MIME 유형이나 원래 사용자 파일 이름도 얻지 못합니다. *이 작업을 위해 제 3 자 업로드 위젯을 사용하라고 촉구합니다. – Charles

답변

0

그냥 첨부 파일 아래 등 메일

move_uploaded_file(string $filename , string $destination); 

와보다 파일을 업로드 :

require("class.phpmailer.php"); 
$mail = new PHPMailer(); 
$mail->Host = 'smtp_host';  
$mail->Port = 'smtp_port'; 
$mail->SMTPAuth = true;   
$mail->Username = 'smtp_user'; // SMTP username 
$mail->Password = 'smtp_pass'; // SMTP password 
$mail->From = "[email protected]"; 
$mail->FromName = "fromName"; 
$mail->AddAddress($email); 
$mail->Subject = "Your subject line"; 
$mail->AddAttachment($source, $fileName); 
$mail->Body = "Your Message"; 

// Send the email. 
if(!$mail->Send()) 
    $message = "Displya some error."; 

} 다음에 대한이 게시물을 무엇