Forums / Developer / Headers in module ?

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

eZ debug

Timing: Jan 18 2025 00:06:44
Script start
Timing: Jan 18 2025 00:06:44
Module start 'content'
Timing: Jan 18 2025 00:06:45
Module end 'content'
Timing: Jan 18 2025 00:06:45
Script end

Main resources:

Total runtime0.8073 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0084 587.6094180.8516
Module start 'content' 0.00840.6840 768.4609538.6641
Module end 'content' 0.69250.1148 1,307.1250332.9141
Script end 0.8073  1,640.0391 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.5154210.0002
Check MTime0.00160.1995210.0001
Mysql Total
Database connection0.00100.125510.0010
Mysqli_queries0.739691.60651940.0038
Looping result0.00180.22641920.0000
Template Total0.781496.820.3907
Template load0.00190.229920.0009
Template processing0.779596.554120.3898
Template load and register function0.00010.014710.0001
states
state_id_array0.00070.087710.0007
state_identifier_array0.00070.091220.0004
Override
Cache load0.00160.1994390.0000
Sytem overhead
Fetch class attribute can translate value0.00140.175630.0005
Fetch class attribute name0.00100.118840.0002
XML
Image XML parsing0.00100.126630.0003
class_abstraction
Instantiating content class attribute0.00000.001240.0000
General
dbfile0.00390.4795280.0001
String conversion0.00000.001230.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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