Search code examples
laravel-4http-headerscontent-typelaravel-routingdownload

Response::download -> Error 500


In Laravel 4.0, I'm trying to create a (forced) download link for a pdf which is located in public/assets/files/cvde.pdf


The view:

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

The route:

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

The controller method:

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"'
        )
    );
}

I'm getting an 500-error and the browser points to public/curry/cvde.

What am I doing wrong?


Solution

  • Firstly, did you manually check if the file is accessible? secondly I believe your request is wrongly formatted:

    /**
         * 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())
        {
                ....
        }