The Storage
facade may be used to interact with any of your configured disks. Alternatively, you may type-hint the Illuminate\Contracts\Filesystem\Factory
contract on any class that is resolved via the Laravel service container.
Retrieving A Particular Disk
$disk = Storage::disk('s3');
$disk = Storage::disk('local');
Determining If A File Exists
$exists = Storage::disk('s3')->exists('file.jpg');
Calling Methods On The Default Disk
if (Storage::exists('file.jpg'))
{
//
}
Retrieving A File's Contents
$contents = Storage::get('file.jpg');
Setting A File's Contents
Storage::put('file.jpg', $contents);
Prepend To A File
Storage::prepend('file.log', 'Prepended Text');
Append To A File
Storage::append('file.log', 'Appended Text');
Delete A File
Storage::delete('file.jpg');
Storage::delete(['file1.jpg', 'file2.jpg']);
Copy A File To A New Location
Storage::copy('old/file1.jpg', 'new/file1.jpg');
Move A File To A New Location
Storage::move('old/file1.jpg', 'new/file1.jpg');
Get File Size
$size = Storage::size('file1.jpg');
Get The Last Modification Time (UNIX)
$time = Storage::lastModified('file1.jpg');
Get All Files Within A Directory
$files = Storage::files($directory);
// Recursive...
$files = Storage::allFiles($directory);
Get All Directories Within A Directory
$directories = Storage::directories($directory);
// Recursive...
$directories = Storage::allDirectories($directory);
Create A Directory
Storage::makeDirectory($directory);
Delete A Directory
Storage::deleteDirectory($directory);