Joh*_*ohn 3 php apache symfony laravel-4
我的文件有UTF-8(希腊语)字符,我无法下载.我正在使用laravel 4.这是我的代码:
//下载
Route::get('file/download', function()
{
$file = 'uploads/????????.odt';
return Response::download($file);
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误(invalidArgumentException)消息:文件名回退必须只包含ASCII字符
关于如何解决这个问题的任何想法..?
这是Response :: download函数中的一个错误.将其更改为:
// File: vendor/laravel/framework/src/Illuminate/Support/Facades/Response.php
public static function download($file, $name = null, array $headers = array(), $disposition = 'attachment')
{
$response = new BinaryFileResponse($file, 200, $headers, true);
if (is_null($name))
{
$name = basename($file);
}
return $response->setContentDisposition($disposition, $name, Str::ascii($name));
}
Run Code Online (Sandbox Code Playgroud)
https://github.com/laravel/framework/pull/4296
Laravel 5
在Laravel 5中,您可以扩展\ Illuminate\Routing\ResponseFactory类并覆盖download()方法.然后,在ServiceProvider中,将自定义ResponseFactory注册为默认值:
// We extends \Illuminate\Routing\ResponseFactory class, that implements Illuminate\Contracts\Routing\ResponseFactory
$this->app->singleton('Illuminate\Contracts\Routing\ResponseFactory', function ($app) {
return new MyCustomResponseFactoryExtendedFromResponseFactory($app['Illuminate\Contracts\View\Factory'], $app['redirect']);
});
Run Code Online (Sandbox Code Playgroud)
这样做,您可以使用默认方法(Response :: json(),respose() - > view()等)和您的自定义方法以相同的方式:Response :: download(),_ response() - > download
| 归档时间: |
|
| 查看次数: |
6085 次 |
| 最近记录: |