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

CakePHP 3-生产站点下载文件路径问题,php,cakephp,download,cakephp-3.0,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 subdirect

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

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'));
}
在我的本地系统上,我可以很好地下载这个文件。然而,在生产服务器上,我遇到了一个障碍,得到了一个蛋糕错误:

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

test excel.xlsx是一个测试excel文件,我上传它来测试我的上传功能(它仍然有效)。所有的斜杠都是朝着同样的方向,而且没有双斜杠,所以我不知道为什么。

我真的不喜欢这种prepend
APP
行为,如果你问我,这是一个混乱和可能的安全问题,我的意思是,我到底为什么要提供位于
src
文件夹中的东西?Brgh。。。我会建议最终摆脱这个。也就是说,只有当给定路径不存在时(如
is_file()
所示),才会发生这种情况,因此
/home/project/public_html/site2/webroot/uploads/files/test excel.xlsx
不存在、不是文件或不可读(检查权限)。发现我的问题-每次部署更新时,我的上载都会被删除(因为我的本地系统在同一目录中没有相同的文件)。但是这个功能很好地工作了。我真的很不喜欢这个prepend
应用程序
的行为,如果你问我,这是一个混乱和可能的安全问题,我的意思是,我到底为什么要提供位于我的
src
文件夹中的东西?Brgh…我建议最终摆脱它。也就是说,只有当给定的路径不存在(如
is_file()
所示),因此
/home/project/public_html/site2/webroot/uploads/files/test excel.xlsx
不存在、不是文件或不可读(检查权限)。发现我的问题-每次部署更新时,我的上载都被删除(因为我的本地系统在同一个目录中没有相同的文件)。