Filesystem

Contents
Disks
Store files
Read back
Public URLs

Disks

Laravel keeps every file location behind one small API called Storage. Each named disk points at a place where files live: the local disk keeps private files inside the storage folder, while the public disk holds files the web server may serve. The disk list lives in the filesystem config file, so adding a disk never changes calling code.

use Illuminate\Support\Facades\Storage; Storage::disk("local")->put("notes.txt", "Hello");

Store files

The put method writes a string to a path and creates missing folders on the way. Pass a folder prefix to keep uploads sorted, and check exists before overwriting data you want to keep.

use Illuminate\Support\Facades\Storage; Storage::put("reports/q1.txt", "Quarter one"); $exists = Storage::exists("reports/q1.txt"); var_dump($exists);

Read back

The get method returns whole file contents as a string, which fits small text files well. Pair it with exists so missing files show a friendly message instead of an exception, and delete files you no longer need.

use Illuminate\Support\Facades\Storage; if (Storage::exists("reports/q1.txt")) { $text = Storage::get("reports/q1.txt"); echo $text; } Storage::delete("notes.txt");

Public URLs

Files on the public disk get a shareable web address through the url method. Store the file name in the database at upload time, then call url again whenever a page needs the link.

use Illuminate\Support\Facades\Storage; $url = Storage::disk("public")->url("avatars/ada.png"); echo $url;

Next: Localization

Article author: Arthur Isaev

Related articles
Development with PHP
What is Laravel and where it runs
Install Laravel
Your first route
Controllers
Blade basics
Blade advanced
Migrations
Eloquent models
Relationships
Query builder
Seeders and factories
Validation
Auth intro
Hand-rolled login
Middleware
Service container
Config and env
Artisan commands
Events and listeners
Queues
Mail
Cache
Sessions in Laravel
CSRF
Hashing
Sanctum tokens
API resources
Gates and policies
Notifications
Scheduler
Filesystem
Localization
Testing
HTTP tests
Collections
Carbon dates
Pagination
File uploads
Eloquent advanced
Transactions and locks
Deployment
Debugbar and dd
Broadcasting
Full-text search
Capstone: blog
Capstone: JSON API
Capstone: shop cart
Performance: kill N+1
Modern Laravel tour
Hero roadmap: the whole course on one page

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: