I have a form with 2 inputs with the same name attribute:
<form enctype="multipart/form-data" method="POST">
<input type="file" name="file_upload" required="required" aria-required="true">
<input type="file" name="file_upload" required="required" aria-required="true">
</form>
Before I had only one upload file input, with PHP I upload that file to temp
folder and attach it to an email using phpMailer
:
if (array_key_exists('file_upload', $_FILES)) {
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['file_upload']['name']));
if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $uploadfile)) {
$mail->addAttachment($uploadfile, $_FILES['file_upload']['name']);
} else{
echo 'Failed!';
exit;
}
}
How to do the same for 2 file inputs?
Both files are required.
Would it be better to use different name for one of them and repeat the same PHP code?