Remove image meta data
- Reading the image and re-saving the image removes the metadata. - This meta data is removed to protect privacy
This commit is contained in:
parent
52352dec39
commit
8c94548bfa
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2023
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2024
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
|
|
@ -55,6 +55,7 @@
|
|||
//get http post variables and set them to php variables
|
||||
if (!empty($_POST)) {
|
||||
|
||||
//set the variables
|
||||
$attachment = $_FILES['attachment'];
|
||||
$attachment_primary = $_POST['attachment_primary'];
|
||||
$attachment_description = $_POST['attachment_description'];
|
||||
|
|
@ -67,6 +68,7 @@
|
|||
exit;
|
||||
}
|
||||
|
||||
//get the attachment type
|
||||
if (empty($attachment) || sizeof($attachment) == 0) {
|
||||
$attachment_type = strtolower(pathinfo($_POST['attachment_filename'], PATHINFO_EXTENSION));
|
||||
}
|
||||
|
|
@ -89,15 +91,50 @@
|
|||
$allowed_primary_attachment = true;
|
||||
}
|
||||
|
||||
//format array
|
||||
//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)) {
|
||||
//create the image object from the content string
|
||||
$image = imagecreatefromstring($attachment_content);
|
||||
|
||||
//start output buffering to capture the image data
|
||||
ob_start();
|
||||
|
||||
//output the image without the EXIF data
|
||||
imagepng($image);
|
||||
|
||||
//get the image from the buffer
|
||||
$attachment_content = ob_get_contents();
|
||||
|
||||
//end the buffering
|
||||
ob_end_clean();
|
||||
|
||||
//free up the memory
|
||||
imagedestroy($image);
|
||||
}
|
||||
}
|
||||
|
||||
//prepare the array
|
||||
$array['contact_attachments'][0]['contact_attachment_uuid'] = $action == 'update' ? $contact_attachment_uuid : uuid();
|
||||
$array['contact_attachments'][0]['domain_uuid'] = $_SESSION['domain_uuid'] ?? '';
|
||||
$array['contact_attachments'][0]['contact_uuid'] = $contact_uuid;
|
||||
$array['contact_attachments'][0]['attachment_primary'] = $allowed_primary_attachment ? 1 : 0;
|
||||
if ($attachment['error'] == '0' && in_array(strtolower(pathinfo($attachment['name'], PATHINFO_EXTENSION)), $allowed_extensions)) {
|
||||
$array['contact_attachments'][0]['attachment_filename'] = $attachment['name'];
|
||||
$array['contact_attachments'][0]['attachment_content'] = base64_encode(file_get_contents($attachment['tmp_name']));
|
||||
$array['contact_attachments'][0]['attachment_content'] = base64_encode($attachment_content);
|
||||
}
|
||||
$array['contact_attachments'][0]['attachment_description'] = $attachment_description;
|
||||
if ($action == 'add') {
|
||||
|
|
@ -116,7 +153,6 @@
|
|||
message::add($text['message-'.($action == 'update' ? 'update' : 'uploaded')]);
|
||||
header('Location: contact_edit.php?id='.$contact_uuid);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
//get form data
|
||||
|
|
|
|||
Loading…
Reference in New Issue