Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PublicAttachmentController.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Controllers\Attachments;
  3. use BusinessLogic\Attachments\Attachment;
  4. use BusinessLogic\Attachments\AttachmentRetriever;
  5. use BusinessLogic\Exceptions\ApiFriendlyException;
  6. class PublicAttachmentController {
  7. static function getRaw($trackingId, $attachmentId) {
  8. global $hesk_settings, $applicationContext, $userContext;
  9. self::verifyAttachmentsAreEnabled($hesk_settings);
  10. /* @var $attachmentRetriever AttachmentRetriever */
  11. $attachmentRetriever = $applicationContext->get[AttachmentRetriever::class];
  12. $attachment = $attachmentRetriever->getAttachmentContentsForTrackingId($trackingId, $attachmentId, $userContext, $hesk_settings);
  13. /* @var $metadata Attachment */
  14. $metadata = $attachment['meta'];
  15. // Send the file as an attachment to prevent malicious code from executing
  16. header("Pragma: "); # To fix a bug in IE when running https
  17. header("Cache-Control: "); # To fix a bug in IE when running https
  18. header('Content-Description: File Transfer');
  19. header('Content-Type: application/octet-stream');
  20. header('Content-Length: ' . $metadata->fileSize);
  21. header('Content-Disposition: attachment; filename=' . $metadata->displayName);
  22. print $attachment['contents'];
  23. }
  24. private static function verifyAttachmentsAreEnabled($heskSettings) {
  25. if (!$heskSettings['attachments']['use']) {
  26. throw new ApiFriendlyException('Attachments are disabled on this server', 'Attachments Disabled', 404);
  27. }
  28. }
  29. }