Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RizwanShahzada012's avatar

Download File into storage directory laravel

i have an dynamic URL, and by hitting this url, a csv file is downloaded into downloads folder of system. but i want to write logic into laravel so when we call this url the file must be downloaded into storage or public directory. so i can play around with this file.

return Redirect::to($url);

i tried with this method, but as i mentioned, the file will be downloaded, but in downloads folder of my computer. i want to download in storage folder of my laravel project.

0 likes
8 replies
bobbybouwmann's avatar

@RizwanShahzada012 Well, you need to store the content of the URL. You can simply do that like so

Storage::put(public_path('files/file.csv'), file_get_contents($url));
bicicura's avatar

Hello there! Maybe you could create a laravel Disk and do a symbolic link with a folder in the public directory.

In Config/filesystems.php at line 20 you will see the "Filesystem Disks" section, you could add something like

'foo' => [
            'driver' => 'local',
            'root' => storage_path('app/foo'),
            'url' => env('APP_URL').'/foo',
            'visibility' => 'public',
        ],	

Then at the bottom of the file at "Symbolic links" section add:

 'links' => [
        public_path('foo') => storage_path('app\foo'),
    ],

Finally type this command on the terminal: ​​php artisan storage:link

Now every file stored at storage/app/foo folder will be available at the public directory public/foo due to this symbolic link.

Extra: as it is a laravel disk you may use methods like

$file->store('/', 'foo');

Using this will store the file at the disk Foo thus, it will be visible at the public directory foo also. Hope this gets the job done or at least give you a hint, byeeee

RizwanShahzada012's avatar

@bicicura my problem is not getting the file form storage folder and link to public, my problem is that, i want to download a file directly into storage or public folder of laravel project

rintoug's avatar

I have achieved it in a non-Laravel way, and for me, it was a single-time usage feature to download some of the files from another server, and do some work in the Laravel project.

copy($url, $destination);

Please or to participate in this conversation.