【问题标题】:Kohana 3.2 Response::send_file seems broken to meKohana 3.2 Response::send_file 对我来说似乎坏了
【发布时间】:2012-06-19 05:04:36
【问题描述】:

我正在尝试将文件发送到浏览器进行下载,但在控制器中使用 $this->response->send_file($file_path); 时运气不佳。

我收到以下错误:

ErrorException [ Warning ]: finfo::file() [<a href='finfo.file'>finfo.file</a>]: Empty filename or path

$file_path 可以是绝对路径或相对路径,但我仍然遇到相同的错误。在查看了此实现的 Kohana 代码后,我无法弄清楚它应该如何工作。

以下代码将显示基本文件名(例如,filename.ext)如何传递到 File::mime() - 这是错误的

https://github.com/kohana/core/blob/3.2/develop/classes/kohana/response.php#L434-453

// Get the complete file path
$filename = realpath($filename);

if (empty($download))
{
    // Use the file name as the download file name
    $download = pathinfo($filename, PATHINFO_BASENAME);
}

// Get the file size
$size = filesize($filename);

if ( ! isset($mime))
{
    // Get the mime type
    // HERE'S THE ISSUE!!!
    $mime = File::mime($download);
}

File::mime 期望文件路径是文件系统上的绝对路径或相对路径,但 $download 只会是基本文件名(例如 filename.ext);

目前唯一对我有用的解决方案是更改 send_file() 方法“classes/kohana/response.php”中的代码

来自File::mime($download);$mime = File::mime($filename);

Kohana 3.3 已将此实现更改为:

$mime = File::mime_by_ext(pathinfo($download, PATHINFO_EXTENSION));

如果没有此修复,基本上 send_file 在 3.2 中不起作用。这是一个错误,还是我在这里遗漏了什么?

【问题讨论】:

  • 干杯@biakaveron 在研究了一些之后,我发现我正在使用并链接到 3.2 开发分支。 3.2 master 分支不存在这个问题。这完全是我自己的错误。

标签: kohana kohana-3 kohana-3.2


【解决方案1】:

我正在使用并链接到 3.2 开发分支。 3.2 master分支不存在此问题。

对于那些感兴趣的人,请关注有关此拉取请求的讨论以查看最终修复:https://github.com/kohana/core/pull/183

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    相关资源
    最近更新 更多