Headers in module ?

Author Message

Fou Jino

Tuesday 01 March 2011 6:35:42 am

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 !

Foujino ~ http://www.foujino-blog.be

Peter Keung

Tuesday 01 March 2011 8:15:19 am

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.

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

Fou Jino

Wednesday 02 March 2011 1: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 :)

Foujino ~ http://www.foujino-blog.be

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.