get[AttachmentRetriever::class]; $attachment = $attachmentRetriever->getAttachmentContentsForTrackingId($trackingId, $attachmentId, $userContext, $hesk_settings); /* @var $metadata Attachment */ $metadata = $attachment['meta']; // Send the file as an attachment to prevent malicious code from executing header("Pragma: "); # To fix a bug in IE when running https header("Cache-Control: "); # To fix a bug in IE when running https header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Length: ' . $metadata->fileSize); header('Content-Disposition: attachment; filename=' . $metadata->displayName); print $attachment['contents']; } private static function verifyAttachmentsAreEnabled($heskSettings) { if (!$heskSettings['attachments']['use']) { throw new ApiFriendlyException('Attachments are disabled on this server', 'Attachments Disabled', 404); } } }