【问题标题】:CakePHP download file errorCakePHP 下载文件错误
【发布时间】:2014-09-25 14:59:54
【问题描述】:

所以基本上我正在尝试下载文件。

我已经行动了:

public function getfile() {
        $this->autoRender = false;
        $accesskey = 'mrPQVeJF8VFXpSq';
        $data = $this->File->find('first', array('conditions' => array('File.accesskey =' => $accesskey)));   

        $filepath = substr($data['File']['path'], 17);

        $this->response->file($filepath, array('download' => true, 'name' => $data['File']['name']));

         return $this->response;
    }

这会引发错误:(我猜是 $this->response->file() 的行)

致命错误错误:找不到类“文件”文件: C:\wamp\www\project\lib\Cake\Network\CakeResponse.php 行:1347

【问题讨论】:

    标签: cakephp download


    【解决方案1】:

    File 类是 Utility of cake。因此,将其用作模型可能会给您带来麻烦。我建议你改变它。阅读更多关于储备蛋糕和 php 字词here。这可能是您的错误的原因。

    导致该错误的另一个原因是您不在 FilesController 中,并试图在那里调用 Find 模型。阅读如何从其他控制器加载模型(查找 ClassRegistry::init$this->loadModel()

    我只是在这里猜测,因为您“猜测引起麻烦的线路是$this->response->file()”。如果您没有准确地猜测和调试给您该错误的行,您可能会得到更准确的响应。

    【讨论】:

      猜你喜欢
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-15
      • 2018-04-21
      相关资源
      最近更新 更多