CakePHP 3 - 生产站点下载文件路径问题

时间:2017-04-10 13:30:08

标签: php cakephp download cakephp-3.0

在我的一个控制器(文件)中,我有一个下载功能如下:

public function download($id = null)
{
    $latestDownload = $this->Files->find('all', ['order' => ['created' => 'DESC']])->first();
    $filePath = WWW_ROOT. 'uploads/files'; //the uploads folder is a subdirectory of webroot; files is a subdirectory of uploads.
    $this->response->file($filePath . DS . $latestDownload->name,
        array('download' => true, 'name' => $latestDownload->name));

    $this->set(compact('latestDownload'));
}

在我的本地系统上,我可以正常下载此文件。但是在生产服务器上,我遇到了麻烦并得到了一个Cake错误:

The requested file /home/project/public_html/site2/src//home/project/public_html/site2/webroot/uploads/files/test excel.xlsx was not found or not readable

测试excel.xlsx是我上传的测试Excel文件,用于测试我的上传功能(仍然有效)。所有斜杠都面向同样的方式,没有双斜线,所以我不确定为什么APP is still being prepended to the path

0 个答案:

没有答案