note 85789 added to function.readfile

From: Date: Wed, 17 Sep 2008 19:40:16 +0000
Subject: note 85789 added to function.readfile
Groups: php.notes 
Request: Send a blank email to php-notes+get-144495@lists.php.net to get a copy of this message
When using readfile with Zend Framework (or any other popular MVC for that matter), you must not follow the built-in httpEquiv or view pattern but rather write your own php to get readfile to work. You must also include a call to 'die' otherwise the script will continue following the MVC pattern and readfile will produce errors. This is not the fault of readfile, but the fault of the current MVC frameworks. Here is a sample action that retrieves and displays a prompt box (open/save) for a specific pdf. <?php public function fddAction() { // get attachment location $attachment_location = $_SERVER["DOCUMENT_ROOT"] . "/pdf/fdd/sample.pdf"; if (file_exists($attachment_location)) { // attachment exists // send open/save pdf dialog to user header('Cache-Control: public'); // needed for i.e. header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="sample.pdf"'); readfile($attachment_location); die(); // stop execution of further script because we are only outputting the pdf } else { die('Error: File not found.'); } } ?> ---- Server IP: 208.69.120.35 Probable Submitter: 65.106.146.42 ---- Manual Page -- http://www.php.net/manual/en/function.readfile.php Edit -- https://master.php.net/note/edit/85789 Del: integrated -- https://master.php.net/note/delete/85789/integrated Del: useless -- https://master.php.net/note/delete/85789/useless Del: bad code -- https://master.php.net/note/delete/85789/bad+code Del: spam -- https://master.php.net/note/delete/85789/spam Del: non-english -- https://master.php.net/note/delete/85789/non-english Del: in docs -- https://master.php.net/note/delete/85789/in+docs Del: other reasons-- https://master.php.net/note/delete/85789 Reject -- https://master.php.net/note/reject/85789 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144495) next »