ダウンロードするファイルをブラウザに送信しようとしていますが$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では機能しません。これはバグですか、それともここで何が欠けていますか?