39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\Mail;
|
|
use App\Entity\Mailing;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
use Symfony\Component\HttpKernel\KernelInterface;
|
|
use App\Entity\MailAttachment;
|
|
|
|
class MailAttachmentController extends AbstractController
|
|
{
|
|
/**
|
|
* @Route("/attachment/{mail}/{attachment}/download", name="attachment_download")
|
|
* @ParamConverter("attachment", options={"mapping": {"id": "attachment", "mail": "mail"}})
|
|
*/
|
|
public function download(MailAttachment $attachment, KernelInterface $kernel): Response
|
|
{
|
|
$mail = $attachment->getMail();
|
|
$mailing = $mail->getMailing();
|
|
$filename = $attachment->getFilename();
|
|
|
|
$path = $kernel->getProjectDir().'/private/attachments/'.$mailing->getId().'/'.$mail->getId().'/'.$filename;
|
|
|
|
return new BinaryFileResponse(
|
|
$path,
|
|
200,
|
|
[
|
|
'Content-Type' => $attachment->getContentType(),
|
|
'Content-Disposition' => sprintf('inline; filename="%s"', $filename),
|
|
]
|
|
);
|
|
}
|
|
}
|