I'm trying to extend this script with a file-upload form: Ajax Contact Form on GitHub After the successfull implementation of PHPMailer, I thought it would be fun to add a new file-upload form. But I do not get it to run.
I've added a new form field into the index.html:
<div class="form-group" id="file1-field">
<label for="form-file1" class="col-lg-2 control-label">Dateianhang</label>
<div class="col-lg-10">
<input type="file" class="form-control" id="form-file1" name="form-file1">
</div>
</div>
Afterwards I've added the contentType and processData lines into the *.js file.
$.ajax({
type : 'POST',
url : 'php/process.php',
data : formData,
dataType : 'json',
contentType : false,
processData : false,
encode : true
})
In the last step I've added these lines into the php script:
if(is_array($_FILES)) {
$mail->AddAttachment($_FILES['form-file1']['tmp_name'],$_FILES['form-file1']['name']);
}
I have googled around and tryied everything, but I can't get any data out of it. The whole form script breaks.
I hope you can help me. Thanks in advance.