How to Download Image or File In Laravel 9

Hello Artisan,

In this tutorial, I will show you how to download images or files in Laravel 9. In this section, I will see how to download Laravel 9. There is two way you can download the image in Laravel 9. First, you can use HTML download Attribute. Second, you can use the Laravel download method.

There is a helper called response()->download() function, using that, we can easily download files in Laravel. See the below example to understand:

You can download files in Laravel using HTML download Attribute. Using this mechanism, you can download file from URL in Laravel:

< a href="{{ Storage::url($file->image)}}" download >Download< /a >

 

Or you can download the image by creating a route like:

public function downloadImage(Image $image)
{
    $imagePath = Storage::url($image->image);

    return response()->download(public_path($imagePath));
}

 

Read also: Laravel 9 Repository Design Pattern Example Tutorial

 

Hope it can help you.

 

author-image
Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js