diff --git a/core/contacts/contact_attachment_edit.php b/core/contacts/contact_attachment_edit.php index 23642505a0..62b05e1d08 100644 --- a/core/contacts/contact_attachment_edit.php +++ b/core/contacts/contact_attachment_edit.php @@ -70,15 +70,15 @@ //get the attachment type if (empty($attachment) || sizeof($attachment) == 0) { - $attachment_type = strtolower(pathinfo($_POST['attachment_filename'], PATHINFO_EXTENSION)); + $attachment_extension = strtolower(pathinfo($_POST['attachment_filename'], PATHINFO_EXTENSION)); } else { - $attachment_type = strtolower(pathinfo($attachment['name'], PATHINFO_EXTENSION)); + $attachment_extension = strtolower(pathinfo($attachment['name'], PATHINFO_EXTENSION)); } //unflag others as primary $allowed_primary_attachment = false; - if ($attachment_primary && ($attachment_type == 'jpg' || $attachment_type == 'jpeg' || $attachment_type == 'gif' || $attachment_type == 'png')) { + if ($attachment_primary && ($attachment_extension == 'jpg' || $attachment_extension == 'jpeg' || $attachment_extension == 'gif' || $attachment_extension == 'png')) { $sql = "update v_contact_attachments set attachment_primary = 0 "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and contact_uuid = :contact_uuid "; @@ -94,29 +94,41 @@ //get the allowed extensions $allowed_extensions = array_keys(json_decode($_SESSION['contact']['allowed_attachment_types']['text'], true)); - //get the attachment extension - $attachment_extension = strtolower(pathinfo($attachment['name'], PATHINFO_EXTENSION)); - //check the allowed extensions if ($attachment['error'] == '0' && in_array($attachment_extension, $allowed_extensions)) { //get the attachment content $attachment_content = file_get_contents($attachment['tmp_name']); - //list of image extensions - $image_extensions = array('png','jpg','jpeg','gif','bmp', 'webp'); - //read the image from the string then output the image without meta data - if (in_array($attachment_extension, $image_extensions)) { + if (in_array($attachment_extension, ['png','jpg','jpeg','gif','bmp', 'webp'])) { //create the image object from the content string $image = imagecreatefromstring($attachment_content); - imagealphablending($image, FALSE); - imagesavealpha($image, TRUE); //start output buffering to capture the image data ob_start(); //output the image without the EXIF data - imagepng($image); + switch ($attachment_extension) { + case 'png': + imagealphablending($image, FALSE); + imagesavealpha($image, TRUE); + imagepng($image); + break; + case 'jpg': + case 'jpeg': + imagejpeg($image); + break; + case 'gif': + imagesavealpha($image, TRUE); + imagegif($image); + break; + case 'bmp': + imagebmp($image); + break; + case 'webp': + imagewebp($image); + break; + } //get the image from the buffer $attachment_content = ob_get_contents(); @@ -215,11 +227,11 @@ echo " ".$text['label-attachment']."\n"; echo "\n"; echo "\n"; - $attachment_type = strtolower(pathinfo($attachment_filename ?? '', PATHINFO_EXTENSION)); + $attachment_extension = strtolower(pathinfo($attachment_filename ?? '', PATHINFO_EXTENSION)); if ($action == 'update') { echo "\n"; - if ($attachment_type == 'jpg' || $attachment_type == 'jpeg' || $attachment_type == 'gif' || $attachment_type == 'png') { - echo ""; + if ($attachment_extension == 'jpg' || $attachment_extension == 'jpeg' || $attachment_extension == 'gif' || $attachment_extension == 'png') { + echo ""; } else { echo "".$attachment_filename.""; @@ -233,7 +245,7 @@ echo "\n"; echo "\n"; - if ($action == 'update' && ($attachment_type == 'jpg' || $attachment_type == 'jpeg' || $attachment_type == 'gif' || $attachment_type == 'png')) { + if ($action == 'update' && ($attachment_extension == 'jpg' || $attachment_extension == 'jpeg' || $attachment_extension == 'gif' || $attachment_extension == 'png')) { echo "\n"; echo "\n"; echo " ".$text['label-attachment_filename']."\n";