I am trying to attach multiple images in the attachments. I have used forearch for every attachment but, its not getting the tempname and name when I use foreach, I'm probably doing something wrong. Below is the code and errors:
Input HTML
<input id="upload-file" class="upload-file" type="file" name="upload-file[]">
var_dump of $_FILES['upload-file']:
array(5) { ["name"]=> array(1) { [0]=> string(47) "WRANGLER_AW13_GIRLONTOP_A4_LANDSCAPE_300dpi.jpg" } ["type"]=> array(1) { [0]=> string(10) "image/jpeg" } ["tmp_name"]=> array(1) { [0]=> string(24) "C:\xampp\tmp\php41DC.tmp" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(91742) } }
var_dump for name and temp_name:
Notice: Undefined index: name in C:\xampp\htdocs\hmg\process-email.php on line 66
Notice: Undefined index: tmp_name in C:\xampp\htdocs\hmg\process-email.php on line 67
NULL
NULL
CODE:
foreach($_FILES['upload-file'] as $file) {
$name = $file['name'];
$path = $file['tmp_name'];
var_dump($name);
var_dump($path);
//And attach it using attachment method of PHPmailer.
$mail->addattachment($path,$name);
}
move_uploaded_file
for more info; there’s a whole chapter in the PHP docs about this. – Alleen