Possible Duplicate:
submit success but upload not work at combine form
I am using the code from here from under the title "Submitting only the file". The code is really simple and small, but when I console.log the "file", it doesn't have a location, webkitrelativepath is "", I can see the file name, size etc on submission. I need to post it into my feedback.php file and attach it to an e-mail from there, but I don't know how to take the file out of the formData and upload it to say my uploads folder so I can then e-mail it...
Thanks.
EDIT:
What code I am using at the moment:
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);
}
});
and in my 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);
}
This doesn't upload or attach any files anywhere...