Filesystem Configuration
Configure storage disks and drivers.
Filesystem configuration lives in config/filesystems.php. Define named disks for different storage needs.
Full Configuration Example #
return [
// Default disk name
'default' => env('FILESYSTEM_DISK', 'local'),
// Disk definitions
'disks' => [
// Private application storage
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
'permissions' => 0755,
],
// Public uploads (web-accessible)
'public' => [
'driver' => 'local',
'root' => base_path('public/uploads'),
'url' => '/uploads',
'permissions' => 0755,
],
// Temporary files
'temp' => [
'driver' => 'local',
'root' => storage_path('temp'),
'permissions' => 0755,
],
// Backups (outside web root)
'backups' => [
'driver' => 'local',
'root' => storage_path('backups'),
'permissions' => 0700,
],
],
];
Configuration Options #
default #
The disk used when no disk is specified:
$storage = app('storage'); // Uses default disk
$storage->disk('public'); // Uses specific disk
disks.*.driver #
Currently supported: local
The local driver stores files on the server's filesystem.
disks.*.root #
Absolute path to the disk's root directory. All operations are relative to this path.
Use helper functions for portability:
storage_path('...')- relative tostorage/base_path('...')- relative to project root
disks.*.url #
Base URL for public disks. Used when generating URLs to stored files:
$url = $storage->disk('public')->url('images/photo.jpg');
// "/uploads/images/photo.jpg"
disks.*.permissions #
Directory permissions for newly created directories. Default: 0755
Use stricter permissions (0700) for sensitive storage like backups.
Usage Examples #
$storage = app('storage');
// Write to default disk
$storage->put('data/config.json', json_encode($config));
// Write to specific disk
$storage->disk('public')->put('uploads/avatar.jpg', $imageData);
// Read file
$content = $storage->get('data/config.json');
// Check existence
if ($storage->exists('data/config.json')) {
// ...
}
// Delete
$storage->delete('temp/cache.tmp');
// Get public URL
$url = $storage->disk('public')->url('uploads/avatar.jpg');
Multi-Tenancy Behavior #
When tenancy is enabled, paths using storage_path() automatically resolve under the tenant's directory:
// Without tenancy: storage/app
// With tenant 123: storage/tenants/123/app
'root' => storage_path('app'),
Security Considerations #
- Private disks should be outside the web root (
storage/app) - Public disks must be inside
public/to be accessible - Set appropriate permissions to prevent unauthorized access
- Validate filenames before storing user uploads
Environment Variables #
FILESYSTEM_DISK=local