eZ Community » Forums » Developer » Headers in module ?
expandshrink

Headers in module ?

Headers in module ?

Tuesday 01 March 2011 3:35:42 pm - 2 replies

Hi everyone,

I have a probleme, I have a page which with a list of PDF document in my root, and I created a module. In fact I want to put header in this module to force download the PDF files but it's doesn't work :s

Here my module (doc/download) :

$module =& $Params['Module'];

$path = "/opt/app/a353/apache-tst/htdocs/portantwerppdf/";

$file = "201102251800_Nota_Antwerpen.pdf";

if(!file_exists($path.$file)) {

die('Error: File not found.'); }

else {

header('Pragma: public'); header('Expires: 0');

header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

header('Cache-Control: private',false);

header('Content-Type: application/pdf');

header('Content-Disposition: attachment; filename="'.$file.'"');

header('Content-Transfer-Encoding: binary');

header('Content-Length: '.filesize($path.$file));

readfile($path.$file); exit();

}

o you have a solution o can you help me ?

Thanks !

Tuesday 01 March 2011 5:15:19 pm

The proper way to stop further eZ Publish execution is to use eZExecution::cleanExit(); instead of die(); or exit(); Perhaps that is what you are missing.

Wednesday 02 March 2011 10:08:59 am

Nop Peter, but I found a solution ;

ob_start();

$path = "[...]";

$file = "[...]"

$filesize = filesize($path.$file);

if(file_exists($path.$file)) {

header('Content-type: application/force-download');

header('Content-disposition: attachment; filename="'. $file .'"');

header('Content-length: '. $filesize ); readfile( $path.$file );

}

ob_end_flush();

I used ob_start() & ob_flush to active output buffering, and it works perfectly happy.gif Emoticon

Modified on Wednesday 02 March 2011 10:09:27 am by Fou Jino

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from