I have a form, with a input files element.
I would like to select a file with this element and send it via ajax to antother php file:
** HTML **
<form enctype="multipart/form-data">
<input type="file" id="angebote" name="angebote[]" accept=".pdf" multiple />
</form>
** Script **
var form_data = new FormData();
for (var index = 0; index < $('#angebote').prop('files').length; index++) {
form_data.append("angebote[]", $('#angebote').prop('files')[index]);
}
$.ajax({
url: 'ajax/sendAnforderung.php',
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(response){
//...
}
});
** PHP **
print_r($_FILES);
** Result **
Array
(
[angebote] => Array
(
[name] => Array
(
[0] => scan.pdf
)
[type] => Array
(
[0] => application/pdf
)
[tmp_name] => Array
(
[0] => /volume1/@tmp/phpiZrjNh
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 509145
)
)
)
Now I would like to send this file as an attachment via php mailer.
for this I nee the path of the file.
I tried this:
echo $_FILES['angebote']['tmp_name'][0]."https://stackoverflow.com/".$_FILES['angebote']['name'][0];
Result:
/volume1/@tmp/phpiZrjNh/scan.pdf
But the file is not be accessable.
Where is my mistake?
Source link
javascript,php,jquery,phpmailer
#javascript #send #uploaded #file #phpmailer