I'm creating dynamically a pdf file and sending it to the client:
private function createPdf($foo)
{
//Delete pdf file if it exists
if(file_exists('path_to_directory' . $foo->getId() . '.pdf'))
unlink('path_to_directory' . $foo->getId() . '.pdf');
//Create new pdf file
$this->get('knp_snappy.pdf')->generateFromHtml(
$this->renderView(
'AcmeFooBundle:Default:pdfTemplate.html.twig', array(
'foo' => $foo)
),
'path_to_directory' . $foo->getId() . '.pdf'
);
// open the file in a binary mode
$fp = fopen('path_to_directory' . $foo->getId() . '.pdf', 'rb');
header("Content-Type: application/pdf");
header('Content-Disposition: attachment; filename="foo.pdf"');
// dump the picture and stop the script
fpassthru($fp);
exit;
}
This function works right, but I'd want to continue execution after sending the file to the client to render a "success" template and send it to the client. I've tried things like removing exit;
and this: Continue execution after calling php passthru() function, but no success. Any idea?