2012-06-16 40 views
3

我试图发送一个文件到浏览器下载,并没有运气在控制器中使用$this->response->send_file($file_path);Kohana 3.2响应:: send_file似乎打破了我

我得到以下错误:

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

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

将下面的代码演示了如何一个基本文件名(例如,FILENAME.EXT)传递到文件:: 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);

,对我现在的工作的唯一办法是从File::mime($download); 在由send_file()方法“类/ Kohana的/ response.php”

修改代码来$mime = File::mime($filename);

的Kohana 3.3改变了这种实施:

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

基本上由send_file不会在3.2没有此修复程序工作。这是一个错误,或者我在这里错过了什么?

+1

http://dev.kohanaframework.org/issues/4344 – biakaveron

+0

干杯@biakaveron寻找到这个多一些之后,我想通我正在使用并链接到3.2开发分支。这个问题在3.2主分支中不存在。这完全是我自己的错误。 – badsyntax

回答

相关问题