CakePHP 3 - Production site download file path issue

谁说我不能喝 提交于 2019-12-11 06:58:53

问题


In one of my controllers (Files), I have a download function as follows:

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

On my local system, I can download this file just fine. However on the production server, I hit a snag and get a Cake error:

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

With test excel.xlsx being a test Excel file I uploaded to test my upload function (that still works). All the slashes are facing the same way, and there are no double slashes, so I'm not sure why APP is still being prepended to the path.

来源:https://stackoverflow.com/questions/43324554/cakephp-3-production-site-download-file-path-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!