Flysystem Package
Introduction
This section will go over how the Files module integrates with The PHP League's filesystem.
Mount Manager
Disks created in the Files module are automatically configured as mounted file systems. You can access the mounted file system using the disk's slug
:
$contents = $manager->read('local://example_folder/file.jpg');
Retrieving Files
Retrieving files through the mount manager works just the same. Simply use your disk slug and folder:
$contents = $manager->read('local://example_folder/file.jpg');
Check if a file exists:
$exists = $manager->has('local://example_folder/file.jpg');
Storing Files
Writing files to a disk from the Files module works just the same using the mount manager:
$manager->write('local://example_folder/file.text', 'contents');
Updating files:
$manager->update('local://example_folder/file.text', 'new contents');
Directories
Working with directories on a disk from the Files module works just the same using the mount manager too:
foreach ($file in $manager->listContents('local://example_folder')) {
echo $file->name;
}
Creating Directories
When you create a directory with Flysystem on a disk from the Files module the resulting folder will be added automatically to the Files module:
$manager->createDir('My Folder'); // Makes a folder like my_folder named "My Folder"
Folders are always referred to by their slugs in the Files module. Even though they have a name field.{.important}
Deleting Directories
When you delete a directory using the Flysystem from a disk from the Files module the resulting folder and files will be deleted automatically in the Files module:
$manager-> deleteDir('my_folder');