It is to download?
Try this: Route::get('file/download', function() { $file = 'path_to_file.pdf'; return Response::download($file, 418, array('iron','man')); });
418 is status of head, iron and man is head with value.
I do something like check if user may access it, etc. If he has the correct role.
in this case you will need to do this
Route::group(array('before' => 'auth'), function() {
Route::get('file/download', function() {
$file = 'path_to_file.pdf'; return Response::download($file, 418, array('iron','man'));
});
});
Yea, ok, but I also check some other things. The points is that I need the dot in the url as a parameter..
I'm not sure if this is what you want to achieve but you can try by dropping this into your routes:
Route::get('attachments/{file}{extension?}', function($file, $extension = null) {
return 'File: ' . $file . '<br>'
. 'Extension: ' . $extension;
})->where([
'file' => '[a-zA-Z0-9-_]+', // the file name (no dots)
'extension' => '\..+' // include the dot as the first character of extension
]);
That's what I mean! But still it returns a 404.
Strange... it works for me on L4.1
Try making this the only route in your routes.php
temporarily.
Honestly, I don't know what might be the problem. Maybe you have some apache / .htaccess issues.
To summarize:
app/routes.php
Route::get('attachments/{file}{extension?}',
[ 'uses' => 'FilesController@getFile',
'as' => 'file.find'])
->where([
'file' => '[a-zA-Z0-9-_]+',
'extension' => '\..+'
]);
app/controllers/FilesController.php
<?php
class FilesController extends BaseController {
public function getFile($file,$extension) {
return 'File: ' . $file . '<br>'
. 'Extension: ' . $extension;
}
}
And with this setup when I navigate to http://localhost/attachments/DummyFile.pdf
I get:
File: DummyFile
Extension: .pdf
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community