沃梦达 / 编程问答 / php问题 / 正文

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

cakePHP File Download was not found or not readable(cakePHP 文件下载未找到或不可读)

本文介绍了cakePHP 文件下载未找到或不可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经挣扎了一个小时试图解决这个问题.我用它从 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.

这篇关于cakePHP 文件下载未找到或不可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:cakePHP 文件下载未找到或不可读

基础教程推荐