Well, when sending my attachment using PHPMailer, if I do not add an extension after the variable, I can not get the extension of the selected file ie:
$mail->addAttachment($uploadfile)
should send the file, giving its name and type, but sends only the temporary name of the same, which for me is no problem, but since there is no extension the file always arrives as something not readable to the recipient , however if you use something like this:
$mail->addAttachment($uploadfile, 'exemplo.jpg')
, sending is done, the file name changes to "example.jpg" and makes the file readable to the recipient.
Can anyone tell me what error I'm making? I've already been looking for the extension via $_FILES['userfile']['type']
and replace with "example.jpg" but what returns me in the email is "image / jpeg" which does not define the extension, thus continuing the "empty" file.
Warning: I am using codeigniter.
This is my controller code:
if (array_key_exists('userfile', $_FILES)) {;
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
var_dump($uploadfile);
$file_type = $_FILES['userfile']['type'];
$mail->addAttachment($uploadfile);
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
} else {
echo 'Failed to move file to ' . $uploadfile;
}
This is what is returned: