[Laravel] Download file, but server doenst have php_fileinfo

Response::Download() in Laravel 4.x needs php_fileinfo extension. Sometimes web hosting server doesn’t have that extension on, althought it’s default for php 5.4.

so the way to work around is make a response, and add header to it. See code below

1
2
3
4
5
$file = File::get($filepath);
$response = Response::make($file, 200);
$response->header('Content-Type', $item->mime);
$response->header('Content-Disposition','attachment;filename="'.$filename.'"');
return $response;