Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

I do something like check if user may access it, etc. If he has the correct role.

Last updated 2 years ago.
0

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

        });

});

Last updated 2 years ago.
0

Yea, ok, but I also check some other things. The points is that I need the dot in the url as a parameter..

Last updated 2 years ago.
0

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
]);
Last updated 2 years ago.
0

That's what I mean! But still it returns a 404.

Last updated 2 years ago.
0

Strange... it works for me on L4.1

Try making this the only route in your routes.php temporarily.

Last updated 2 years ago.
0

Thanks it works. Was a Nginx conf issue.

Last updated 2 years ago.
0

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
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

renege renege Joined 7 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.