Retain uploaded extension in the attachment examples so that the MIME type is more easily obtained
This commit is contained in:
parent
600bcde8a8
commit
f6321480c5
|
|
@ -12,7 +12,11 @@ if (array_key_exists('userfile', $_FILES)) {
|
|||
// First handle the upload
|
||||
// Don't trust provided filename - same goes for MIME types
|
||||
// See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name']));
|
||||
// Extract an extension from the provided filename
|
||||
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
|
||||
// Define a safe location to move the uploaded file to, preserving the extension
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'])) . '.' . $ext;
|
||||
|
||||
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
|
||||
// Upload handled successfully
|
||||
// Now create a message
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@ if (array_key_exists('userfile', $_FILES)) {
|
|||
$mail->addAddress('whoto@example.com', 'John Doe');
|
||||
$mail->Subject = 'PHPMailer file sender';
|
||||
$mail->Body = 'My message body';
|
||||
//Attach multiple files one by one
|
||||
// Attach multiple files one by one
|
||||
for ($ct = 0, $ctMax = count($_FILES['userfile']['tmp_name']); $ct < $ctMax; $ct++) {
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct]));
|
||||
// Extract an extension from the provided filename
|
||||
$ext = PHPMailer::mb_pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
|
||||
// Define a safe location to move the uploaded file to, preserving the extension
|
||||
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct])) . '.' . $ext;
|
||||
$filename = $_FILES['userfile']['name'][$ct];
|
||||
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
|
||||
if (!$mail->addAttachment($uploadfile, $filename)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue