Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have upload area for my customers which files should be private and not public accessible. Because of non-public availability, how can I get this files for preview in application? Is there any other way to get it directly from server?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are working with images:

Route::get('/file/download', function() {
    // get your filepath
    $filepath = 'path/to/image/image.png';
    return Response::download($filepath);
});

Then in your view:

<img src="{{url('/file/download')}}" class="rounded-circle" />

For any other file:

Route::get('/file/download', function() {
    // get your filepath
    $filepath = 'path/to/file/essay.docx';
    return Response::download($filepath);
});

Your view:

<a href="{{url('/file/download/')}}">Download</a>

If you wish you may use a controller:

namespace MyNamespace;

use IlluminateRoutingController;

class FilesController extends Controller
{
    public function downloadFile()
    {
        // get your filepath
        $filepath = 'path/to/file/essay.docx';
        return Response::download($filepath);
    }
}

Then your route definition would look like:

Route::get('/file/download', ['as' => 'file.download', 'uses' => 'MyNamespaceFilesController@downloadFile']);

And your view:

<a href="{{route('file.download')}}">Download</a>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...