问题
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