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(); } $fileType = $attachment->get('type'); if (!in_array($fileType, $this->allowedFileTypes)) { throw new Forbidden("EntryPoint Attachment: Not allowed type {$fileType}."); } if ($attachment->get('type')) { header('Content-Type: ' . $fileType); } header('Pragma: public'); header('Content-Length: ' . filesize($fileName)); readfile($fileName); exit; } }