Monday, May 22, 2017

Download files using Laravel's Storage facade

I've got a directory dl in storage/app/ directory, and I managed to get the files content using Storage::get(dl/filename.ext)
But now I wanna make a download link for those files, and I'm kinda confused by how does Response and Storage facade work.

I'm using Response facade with a defined route like this :

Route::get('site/download/{fileName}', function($fileName) {
    $path = storage_path().'/app/dl/'.$fileName;

    return Response::download($path, $fileName);
});

Note: I'm using Laragon, site is the root directory.
The problem occuring is Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?) . I know this is a known problem but after searching for a solution, I didn't find something that would fit my needs. The files are C files, mime type should be 'text/plain' probably, but I don't know how and where to specify it.
I also looked for other solutions, but file does not exists kept showing up.
I need something to download files from storage/app/dl/.



via Pierre Lartigau

Advertisement