【问题标题】:PHP - Zend Framework send filePHP - Zend 框架发送文件
【发布时间】:2012-06-25 08:56:26
【问题描述】:

我正在尝试在 Zend Framework PHP 应用程序中向浏览器发送文件。我在这里找到了一个动作助手 - https://github.com/noginn/noginn/blob/master/Noginn/Controller/Action/Helper/SendFile.php

在我的控制器中,我有这样的操作

public function downloadfileAction()
{
    //get the file name and strip out all white spaces
    $title = preg_replace('/\s+/', '', $this->getRequest()->getParam('title')); 

    //create the file path          
    $path = 'downloads/'.$title.'.pdf';

    //call the action helper to send the file to the browser
    $this->_helper->SendFile->sendFile($path, 'application/x-pdf');
}

我的文件位于我的公共文件夹中,即 MyApp/public/downloads/myFile.pdf

当我运行该操作时,我得到一个未找到视图文件的错误并且没有开始下载。

exception 'Zend_View_Exception' with message 'script 'myController/downloadfile.phtml' not found ...

谁能建议我做错了什么?

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    找不到关于脚本(视图)文件的错误。因为发送输出时不需要一个。

    尝试通过以下方式禁用它:

    public function downloadfileAction()
    {
        //get the file name and strip out all white spaces
        $title = preg_replace('/\s+/', '', $this->getRequest()->getParam('title')); 
    
        //create the file path          
        $path = 'downloads/'.$title.'.pdf';
    
        //call the action helper to send the file to the browser
        $this->_helper->SendFile->sendFile($path, 'application/x-pdf');
        $this->_helper->viewRenderer->setNoRender();
    }
    

    【讨论】:

    • 很高兴听到,没问题! :) 不要忘记接受答案,谢谢。 :)
    猜你喜欢
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    • 2011-03-20
    • 2010-11-16
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    相关资源
    最近更新 更多