getEntityManager()->getEntity('Attachment', $id); if (!$attachment) { throw new NotFound(); } if (!$this->getAcl()->checkEntity($attachment)) { throw new Forbidden(); } $fileName = $this->getEntityManager()->getRepository('Attachment')->getFilePath($attachment); if (!file_exists($fileName)) { throw new NotFound(); } if ($attachment->get('type')) { header('Content-Type: ' . $attachment->get('type')); } header('Pragma: public'); header('Content-Length: ' . filesize($fileName)); readfile($fileName); exit; } }