Laravel Download File from URL to Storage Example

By Hardik Savani February 18, 2023 Category : Laravel

Hey Dev,

This article will give you an example of laravel download file from url. If you have a question about laravel download file from url to storage then I will give a simple example with a solution. if you want to see an example of laravel download file from link then you are in the right place. In this article, we will implement a laravel download file from external url.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 versions.

If you need to download a file or image from a URL in laravel, then I will give you a straightforward example of it. We will use Storage facade and file_get_contents() function to download image from url. so let's see the below controller code.

Example:

app/Http/Controllers/DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Storage;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$path = "https://www.itsolutionstuff.com/assets/images/logo-it.png";

Storage::disk('local')->put('itsolutionstuff.png', file_get_contents($path));

$path = Storage::path('itsolutionstuff.png');

return response()->download($path);

}

}

I hope it can help you...

Tags :