FileSystem

Configuration & usage

Flysystem is a file storage library for PHP. It provides one interface to interact with many types of filesystems. When you use Flysystem, you’re not only protected from vendor lock-in, you’ll also have a consistent experience for which ever storage is right for you.

Installation

Flysystem can be installed using composer.

composer require league/flysystem:^3.0

Additionally, you may want to install an extra adapter to interact with specific types of filesystems. Please see the official flysystem documentation.

Configurations

You can choose between many drivers: local, ftp, sftp, memory, awsS3, googleCloudStorage, azureBlobStorage, webdav, zipArchive.

# Local Storage
FILE_SYSTEM_DRIVER=local

# FTP Storage
FILE_SYSTEM_DRIVER=ftp

# SFTP Storage
FILE_SYSTEM_DRIVER=sftp

# Memory Storage
FILE_SYSTEM_DRIVER=memory

# AWS S3 Storage
FILE_SYSTEM_DRIVER=awsS3

# Google Cloud Storage
FILE_SYSTEM_DRIVER=googleCloudStorage

# Azure Blob Storage
FILE_SYSTEM_DRIVER=azureBlobStorage

# WebDAV Storage
FILE_SYSTEM_DRIVER=webdav

# Zip Archive Storage
FILE_SYSTEM_DRIVER=zipArchive

Advanced Settings: Some settings are only available when you use a specific file system driver. Below you can find the advanced settings for each driver.

# Local Storage
FILE_SYSTEM_DRIVER=local

# File System Settings of the `local` driver
FILE_SYSTEM_LOCAL_ROOT_DIRECTORY=<root>
# AWS S3 Storage
FILE_SYSTEM_DRIVER=awsS3

# File System Settings of the `awsS3` driver
FILE_SYSTEM_AWS_S3_BUCKET_NAME=<your-bucket-name>
FILE_SYSTEM_AWS_S3_PATH_PREFIX=<optional-path-prefix>
FILE_SYSTEM_AWS_S3_ASYNC=false

Usage

// if the class is aware of injections
$fileSystem = $this->fileSystem;

// if the container is present
$fileSystem = $this->di->get('fileSystem');

// to access the shared db service
$fileSystem = Di::getDefault()->get('fileSystem');

Sources

Last updated