Depending on your needs you may want to disable Rendering and Layouts:

setNoRender(); & disableLayout();

        /**
         * streamAction
         *
         * Stream Action
        */
        public function streamAction()
        {
                $this->getHelper('ViewRenderer')->setNoRender();
                $this->getHelper('Layout')->disableLayout();            

                $fileString = $this->_request->getParam("fileString");
                $dldFileName = $this->_request->getParam("fileName");
                ...



Goran Dodig wrote:
> 
> Hello there,
> 
> I guess this could help you.
> The way I did it was by making streamAction() in my controller that 
> looks like this:
> 
>     function streamAction()
>     {
>         $fileString = $this->_request->getParam("fileString");
>         $dldFileName = $this->_request->getParam("fileName");
>         $disposition = $this->_request->getParam("fileDisposition"); // 
> can be "inline" or "attachment"
>         $contentType = $this->_request->getParam("fileMime");
> 
>         if ($this->_request->get("HTTPS") !== null) {
>             $this->_response->setHeader("Pragma", "");
>             $this->_response->setHeader("Cache-Control", "");
>             $this->_response->setHeader("Expires", "Mon, 1 Jan 2000 
> 00:00:00 GMT");
>             $this->_response->setHeader("Last-Modified", gmdate("D, d M 
> Y H:i:s") . " GMT");
>             $this->_response->setHeader("Cache-Control", "no-store, 
> no-cache, must-revalidate"); // HTTP/1.1
>             $this->_response->setHeader("Cache-Control", "post-check=0, 
> pre-check=0");
>         } else if ($disposition == "attachment") {
>             $this->_response->setHeader("Cache-control", "private");
>         } else {
>             $this->_response->setHeader("Cache-Control", "no-cache, 
> must-revalidate");
>             $this->_response->setHeader("Pragma", "no-cache");
>             $this->_response->setHeader("Expires", "0");
>         }
> 
>         $agent = trim($this->_request->get("HTTP_USER_AGENT"));
>         if ((preg_match('|MSIE ([0-9.]+)|', $agent, $version)) ||
>             (preg_match('|Internet Explorer/([0-9.]+)|', $agent, 
> $version))) {
> 
>             if    ($disposition == "attachment")
>                 $this->_response->setHeader("Content-Type", 
> "application/x-msdownload");
>             else
>                 $this->_response->setHeader("Content-Type", $contentType);
> 
>             if ($version == '5.5') {
>                 $this->_response->setHeader("Content-Disposition", 
> "filename=".$dldFileName);
>             } else {
>                 $this->_response->setHeader("Content-Disposition", 
> $disposition."; filename=".$dldFileName);
>             }
>         } else {
>             $this->_response->setHeader("Content-Type", $contentType);
>             $this->_response->setHeader("Content-Disposition", 
> $disposition."; filename=" . $dldFileName);
>         }
> 
>         $this->_response->setHeader("Content-Length",
> strlen($fileString));
>         $this->_response->setHeader("Content-transfer-encoding", "8bit");
>         $this->_response->setHeader("Connection", "close");
> 
>         $this->_response->setBody($fileString);
> 
>         $this->render();
> 
>     }
> 
> And than forward to it from wherever i need it like so:
> 
> $this->_forward("stream", "pdf", null, array("fileString" =>
> $pdf->render(),
>                                              "fileName"   => $pdfFile,
>                                              "fileDisposition"   => 
> "inline",
>                                              "fileMime"   => 
> "application/pdf",
>                                              ));
> 
> The code in streamAction takes care of everything, and works in IE5.5, 
> 6.0+, Mozilla, Opera (as far as i could test) and over http as well as 
> https protocol.
> 
> Best regards,
> 
> Goran Dodig
> [EMAIL PROTECTED]
> 
> 
> frederic wolf wrote:
>> Mauro Casula a écrit :
>>> Hi all,
>>>
>>> I have an action that make a mysql database backup in this way:
>>>
>>>      public function backupDatabaseAction()
>>>     {   
>>>         $db = Zend::registry('db');         $view = 
>>> Zend::registry('view');
>>>         $config = Zend::registry('config');
>>>         $session = Zend::registry('session');
>>>        
>>>         $view->title = $config->site->title." - Modifica di una casa";
>>>        
>>>         $ctr = new CaseVacanzaDataController($db, $session);
>>>     
>>>             $view->actionTemplate = 'main.php';             
>>> $view->header = $view->render('header.php');
>>>                          system($config->bin_path."\export_db.bat", 
>>> $ret);              $view->menu =  
>>> $view->render('menu_amministrazione.php');
>>>             $view->body = $view->render('admin_backup_database.php');
>>>
>>>             $view->footer = $view->render('footer.php');
>>>                
>>>             echo $view->render('main.php');
>>>        
>>>
>>>     }
>>>
>>> the export_db.bat script write a Sql backup file in a specific 
>>> directory..
>>>
>>> What I have to do for return this file directly with the download 
>>> popup and
>>> so delete it..?
>>>
>>> Thankyou in advance for the answers..
>>> Regards.
>>> Mauro Casula
>>>     
>>>   
>> Hello,
>>
>> this could help you maybe :
>>
>> basically you could do that
>>        $str = file_get_contents($file);
>>        header('Content-Disposition: attachment; 
>> filename="downloaded.pdf"');
>>        header('Content-type: application/pdf');
>>        echo $str;
>>
>> the example is for a pdf file, in your example, yous hould change 
>> Content-type (look for it in header doc) Content-Disposition: 
>> attachment makes the download window opens in order to save it or 
>> display it on the client side.
>>
>> But  I guess, a "zfer" way would be to use the response object, maybe 
>> like this :
>>
>> |$this->getResponse()
>>    ->setHeader('Content-Type', 'text/plain')
>>    ||->setHeader('|Content-Disposition|', '|attachment; 
>> filename="bkp.sql"'|') |
>> |    ->appendBody(|$str|);
>>
>> Hope this could help you, though I didn't test it. At least it works 
>> for me with pdf files.
>>
>> fred
>>
>>
>> |
>>
>>
>>
>>
> 
> 
>  
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-return-a-file-directly-by-an-action-tp10056561p16751381.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to