Hi y'all!
Im am trying to force a file download after user submits a form. When user hits submit button POST data are send to a template (sort of "thank you for downloading" page). This template on successful submission redirects to another template through this code
<?php
$downloadurl = $pages->get('/download/')->url;
header('refresh: 0; url='.$downloadurl);
?>
Redirection then hits this template code (located in download template):
<?php
// filename & url of the pdf file
$filename = $pages->get('/some-page/')->file->name;
$fileurl = $pages->get('/some-page/')->file->url;
$filesize = $pages->get('/some-page/')->file->filesize;
// force download of the file
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename='.$filename);
header("Content-Length: ".$filesize);
readfile($fileurl);
It downloads a file and then redirects back to thank you page. The only problem is that the downloaded file is empty (0KB). When i download a file "the standard way" clicking on a link that directs to $pages->get('/some-page/')->plik->url; everything is ok.
Any ideas?