download_file.php 435 B

12345678910111213141516171819202122
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use RuntimeException;
  4. /**
  5. * @var string $type
  6. * @var string $id
  7. */
  8. switch($type) {
  9. case "ticket-comment-attachment":
  10. $attachment = TicketCommentAttachment::get($id);
  11. if(!$attachment) {
  12. throw new RuntimeException(__("Attachment not found."));
  13. }
  14. header("Content-Type: $attachment->mime_type");
  15. readfile($attachment->getPath());
  16. exit(0);
  17. }