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.

eZ debug

Timing: Jan 18 2025 02:49:14
Script start
Timing: Jan 18 2025 02:49:14
Module start 'layout'
Timing: Jan 18 2025 02:49:14
Module start 'content'
Timing: Jan 18 2025 02:49:15
Module end 'content'
Timing: Jan 18 2025 02:49:15
Script end

Main resources:

Total runtime1.1771 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 589.2266152.6094
Module start 'layout' 0.00480.0052 741.835939.4375
Module start 'content' 0.01001.1658 781.2734533.6016
Module end 'content' 1.17580.0013 1,314.875012.3438
Script end 1.1771  1,327.2188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00330.2777160.0002
Check MTime0.00140.1159160.0001
Mysql Total
Database connection0.00060.053910.0006
Mysqli_queries1.123995.4817570.0197
Looping result0.00060.0488550.0000
Template Total1.148197.520.5741
Template load0.00240.199820.0012
Template processing1.145897.335520.5729
Template load and register function0.00030.022310.0003
states
state_id_array0.00080.064110.0008
state_identifier_array0.00090.080520.0005
Override
Cache load0.00200.1674390.0001
Sytem overhead
Fetch class attribute can translate value0.00100.080820.0005
Fetch class attribute name0.00130.112140.0003
XML
Image XML parsing0.00080.066920.0004
class_abstraction
Instantiating content class attribute0.00000.000840.0000
General
dbfile0.00120.1044170.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
3content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 9
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs