cakePHP 文件下载未找到或不可读

2021-12-21 00:00:00 php cakephp cakephp-2.0

我已经挣扎了一个小时试图解决这个问题.我用它从 app/uploads/ 目录下载文件.它说找不到目录或不可读.然而我检查了它,它也在那里使用 $file['File']['filename'] 文件.我想知道我在这里遗漏了什么.?

I've been struggling now for an hour trying to fix this. I used this to download file from app/uploads/ directory. It says the directory not found or not readable. Yet i checked it and it was there also the file using $file['File']['filename']. I want to know what I am missing here.?

$file = $this->File->findById($id);

$extension = pathinfo($file['File']['filename'],PATHINFO_EXTENSION);

$this->response->file('uploads'.DS.$file['File']['filename'], array(
    'download' => true,
    'id'       => $file['File']['filename'],
    'name'     => $file['File']['filename']
));
$this->response->type($extension);
return $this->response;

推荐答案

确保您没有其他名为 File 的模型.如果是这样 - 它显然会覆盖 cakephp 的核心实用程序/文件模型.

Make sure you have no other model named File. If so - it apparently overwrites the cakephp's core Utility/File model.

相关文章