Convert Figma logo to code with AI

thephpleague logoflysystem

Abstraction for local and remote filesystems

13,312
825
13,312
71

Top Related Projects

[READYONLY SUB-SPLIT]Flysystem Adapter for AWS SDK V3

Quick Overview

Flysystem is a PHP library that provides a unified filesystem abstraction layer. It offers a simple and consistent API for interacting with various file storage systems, including local filesystems, cloud storage services, and more. Flysystem allows developers to write filesystem-agnostic code, making it easier to switch between different storage backends.

Pros

  • Consistent API across multiple storage adapters
  • Easy to switch between different storage backends without changing application code
  • Extensive adapter support for popular storage services (e.g., Amazon S3, Azure Blob Storage, Google Cloud Storage)
  • Actively maintained and well-documented

Cons

  • Additional abstraction layer may introduce slight performance overhead
  • Some advanced features of specific storage systems may not be accessible through the abstraction
  • Learning curve for developers unfamiliar with the concept of filesystem abstraction

Code Examples

  1. Basic file operations:
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

$adapter = new LocalFilesystemAdapter('/path/to/root');
$filesystem = new Filesystem($adapter);

// Write a file
$filesystem->write('path/to/file.txt', 'Contents');

// Read a file
$contents = $filesystem->read('path/to/file.txt');

// Delete a file
$filesystem->delete('path/to/file.txt');
  1. Using cloud storage (Amazon S3):
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
use League\Flysystem\Filesystem;
use Aws\S3\S3Client;

$client = new S3Client([
    'credentials' => [
        'key'    => 'your-key',
        'secret' => 'your-secret',
    ],
    'region' => 'your-region',
    'version' => 'latest',
]);

$adapter = new AwsS3V3Adapter($client, 'your-bucket-name');
$filesystem = new Filesystem($adapter);

// Upload a file to S3
$filesystem->write('path/to/file.txt', 'Contents');
  1. Listing directory contents:
use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

$adapter = new LocalFilesystemAdapter('/path/to/root');
$filesystem = new Filesystem($adapter);

// List all files in a directory
$contents = $filesystem->listContents('path/to/directory', false);

foreach ($contents as $item) {
    echo $item->path() . "\n";
}

Getting Started

To start using Flysystem, install it via Composer:

composer require league/flysystem

Then, create a filesystem instance with the desired adapter:

use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;

$adapter = new LocalFilesystemAdapter('/path/to/root');
$filesystem = new Filesystem($adapter);

// Now you can use $filesystem to perform file operations
$filesystem->write('example.txt', 'Hello, Flysystem!');

Competitor Comparisons

[READYONLY SUB-SPLIT]Flysystem Adapter for AWS SDK V3

Pros of flysystem-aws-s3-v3

  • Specialized for AWS S3 integration, offering optimized performance
  • Provides access to S3-specific features and functionality
  • Simplifies S3 operations with a consistent API

Cons of flysystem-aws-s3-v3

  • Limited to AWS S3, reducing flexibility for multi-cloud environments
  • Requires additional setup and configuration for S3 credentials
  • May have a steeper learning curve for developers unfamiliar with S3

Code Comparison

flysystem:

$filesystem = new League\Flysystem\Filesystem($adapter);
$filesystem->write('path/to/file.txt', 'contents');
$contents = $filesystem->read('path/to/file.txt');

flysystem-aws-s3-v3:

$client = new Aws\S3\S3Client([/* S3 config */]);
$adapter = new League\Flysystem\AwsS3V3\AwsS3V3Adapter($client, 'bucket-name');
$filesystem = new League\Flysystem\Filesystem($adapter);
$filesystem->write('path/to/file.txt', 'contents');
$contents = $filesystem->read('path/to/file.txt');

The main difference in the code is the setup of the S3 adapter, which requires an S3 client and bucket name. Once configured, both libraries use similar methods for file operations, maintaining a consistent API across different storage systems.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

League\Flysystem

Author Source Code Latest Version Software License Quality Assurance Total Downloads php 7.2+

About Flysystem

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.

Getting Started

Officially supported adapters

Third party Adapters

You can always create an adapter yourself.

Security

If you discover any security related issues, please email info@frankdejonge.nl instead of using the issue tracker.

Enjoy

Oh, and if you've come down this far, you might as well follow me on twitter.