Veldora provides a unified filesystem API for managing files across multiple storage disks. By default, two disks are pre-configured: local (private, server-only) and public (web-accessible via a URL).
Configuration
Disks are defined in config/filesystems.php:
example.php
PHP
return [
'default' => env('FILESYSTEM_DISK', 'local'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'), // storage/app/
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'), // storage/app/public/
'url' => '/storage', // Web URL prefix
],
],
];When to Use Each Disk
| Disk | Path | Web Accessible | Use For |
|---|---|---|---|
local | storage/app/ | ❌ No | Private files: invoices, exports, backups |
public | storage/app/public/ | ✅ Yes (via /storage/) | User-uploaded avatars, images, documents |
Storing Files
example.php
PHP
// Store raw binary content
storage('public')->put('avatars/user-42.png', $binaryContent);
// Store an uploaded file from a request
$file = $request->file('avatar'); // Returns a PHP SplFileInfo instance
$path = 'avatars/' . uniqid() . '.jpg';
storage('public')->put($path, file_get_contents($file->getPathname()));Reading Files
example.php
PHP
// Read raw file contents
$content = storage('local')->get('exports/report.csv');
// Get file size in bytes
$size = storage('local')->size('exports/report.csv');
// Check if file exists
if (storage('public')->exists('avatars/user-42.png')) {
echo 'File found!';
}Generating Public URLs
For files on the public disk, generate a browser-accessible URL:
example.php
PHP
// Returns: /storage/avatars/user-42.png
$url = storage('public')->url('avatars/user-42.png');
// Use in a view:
// <img src="{{ $url }}" alt="Avatar">Deleting Files
example.php
PHP
// Delete a single file
storage('public')->delete('avatars/old-avatar.png');
// Delete multiple files
storage('public')->delete(['thumbs/img1.jpg', 'thumbs/img2.jpg']);Listing Files in a Directory
example.php
PHP
// List all files in a directory
$files = storage('public')->files('avatars');
// List all directories
$dirs = storage('local')->directories('exports');Practical Example — File Upload Controller
example.php
PHP
public function uploadAvatar(Request $request): Response
{
$validated = $request->validated([
'avatar' => 'required',
]);
$user = auth()->user();
$file = $request->file('avatar');
// Delete old avatar if it exists
if ($user->avatar_path && storage('public')->exists($user->avatar_path)) {
storage('public')->delete($user->avatar_path);
}
// Store new avatar
$path = 'avatars/user-' . $user->id . '-' . uniqid() . '.jpg';
storage('public')->put($path, file_get_contents($file->getPathname()));
// Save path to user record
$user->avatar_path = $path;
$user->save();
return Response::redirect('/profile')
->with('success', 'Avatar updated successfully!');
}