dst2007 2012-06-25 08:56
浏览 40
已采纳

PHP - Zend Framework发送文件

I am trying to send a file to the browser in a Zend Framework PHP application. I found an action helper here - https://github.com/noginn/noginn/blob/master/Noginn/Controller/Action/Helper/SendFile.php

In my controller I have an action like this

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');
}

my file is located in my public folder ie MyApp/public/downloads/myFile.pdf

When I run the action, I get a view file not found error and the download is not started.

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

Can anyone suggest what I am doing wrong?

  • 写回答

1条回答 默认 最新

  • drju37335 2012-06-25 09:01
    关注

    It's an error about the script-(view)-file what can't be found. Cause you don't need one when sending output.

    Try disable it by this this:

    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();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类