Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Storage and File Handling

Manage file uploads and storage with Laravel filesystem.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Store File
  2. Store with Name
  3. Get File
  4. Delete File
  5. Check Existence

File storage in Laravel:

Store File

php
$path = $request->file('avatar')->store('avatars');
$path = Storage::disk('s3')->put('avatars', $file);

Store with Name

php
$path = $request->file('avatar')->storeAs(
    'avatars', $user->id.'.jpg'
);

Get File

php
$contents = Storage::get('file.txt');
$url = Storage::url('file.txt');

Delete File

php
Storage::delete('file.txt');
Storage::delete(['file1.txt', 'file2.txt']);

Check Existence

php
if (Storage::exists('file.txt')) {
    // ...
}
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read