【发布时间】:2015-10-29 20:55:10
【问题描述】:
我尝试下载上传的文件,这些文件保存在 webroot 的“文件”文件夹中。这是我在控制器中的下载功能:
public function download($id=null) { $this->response->file(WWW_ROOT . DS .'files'. $id ,array('download'=> true,'id'=> 'file name.pdf',
'name'=> 'file name'));
在视图中我有以下内容:
<td> <?= $this->Html->link('Download', ['controller' => 'Articles', 'action' => 'download',$id]) ?></td>
首先这会导致下载按钮下的错误(未定义的变量 id),然后我得到(更全局的)错误:请求的文件 C:\xampp\htdocs\articles\src\C:\xampp\ htdocs\articles\webroot\files 未找到或不可读。我真的不明白为什么 C:\xampp\htdocs\articles 部分重复两次以及如何解决这些问题并下载上传的文件(不仅是函数 $this->response->file 中的指定文件,还有通过它的 ID)。任何帮助将不胜感激!
【问题讨论】:
-
您是否尝试删除文件路径中的
WWW_ROOT . DS .?
标签: php cakephp cakephp-3.0