回复::下载 - >错误500

时间:2013-12-28 17:16:29

标签: laravel-4 http-headers content-type laravel-routing downloading

Laravel 4.0 中,我正在尝试为位于public/assets/files/cvde.pdf

的pdf创建(强制)下载链接

观点:

<a href="curry/cvde">deutsch</a>

路线:

Route::get('curry/{file}', 'HomeController@downloadCV');

控制器方法:

public function downloadCV($file) {
    return Response::download(public_path() . '/assets/files/' . $file . '.pdf', array(
            'Content-Type'=>'application/octet-stream',
            'Content-Disposition'=>'attachment; filename="' . $file . '.pdf"'
        )
    );
}

我收到500错误,浏览器指向public/curry/cvde

我做错了什么?

1 个答案:

答案 0 :(得分:1)

首先,您是否手动检查文件是否可访问?其次,我认为您的请求格式错误:

/**
     * Create a new file download response.
     *
     * @param  SplFileInfo|string  $file
     * @param  string  $name
     * @param  array   $headers
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
     */
    public static function download($file, $name = null, array $headers = array())
    {
            ....
    }