Abstraction for local and remote filesystems

Last update: May 22, 2022

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

Commonly-Used Adapters

Third party Adapters

You can always create an adapter yourself.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Enjoy

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

GitHub

https://github.com/thephpleague/flysystem
Comments
  • 1. Empty Object for zip

    I get empty Zip object after writing the content from local to zip adapter. No files are listed for the zip object where the source has files.

    Is there any other way to make the object to save the file instead of using null.

    Sorry again for all the trouble.

    $local = new Filesystem(new Local("C:\wamp\www\oxwall\watermark"));
    $zip = new Filesystem(new Zip($zipFilename));
    
    $contents = $local->listContents();
    
    foreach ($contents as $info) {
        if ($info['type'] === 'dir') {
            continue;
        }
    
        $zip->write($info['path'], $local->read($info['path']));
    }
    var_dump($zip->listContents());
    $zip = null;
    
    Reviewed by Purus at 2013-12-03 17:35
  • 2. [FTP Driver] Support for implicit SSL

    Hello,

    current ftp implementation supports only explicit SSL and does not work with implicit SSL connection, which is by default uses 990 port.

    Also, there is no support for implicit SSL in PHP. Research gave me only solution using curl.

    I can make pull request to make implicit SSL connection work using curl. Or community can provide another options?

    Reviewed by vyuldashev at 2017-04-26 13:38
  • 3. Download/Upload-Progress

    When working with mid-size or large files it's actual always required to have a kind of progress information. Especially, when the server has not a big bandwidth or the connection is pretty busy and you want to inform your client/user with a progress-bar while uploading/downloading.

    What do you think about providing such a API? I don't know whether all adapters are able to support that or if we have to emulate it somehow.

    I guess a event-based system would be a good method to achieve that.

    Example:

    $fs = new Filesystem();
    $fs->on('upload', function($bytes, $totalBytes, $path){
        echo sprintf("%s: %d of %d\n", $path, $bytes, $totalBytes);
    });
    
    $fs->write('bla', 'hossa');
    

    What do you think?

    Reviewed by marcj at 2013-11-25 21:25
  • 4. Upload large file (> 1GB) with a local adapter.

    I am trying to upload a large file (> 1GB) with a local adapter.

    I am working on Directus https://github.com/directus/api, an opensource headless CMS.

    I am using Slim as a backend framework.

    There is not a specific example of a handling file for slim in the documentation https://flysystem.thephpleague.com/docs/guides/uploads/ So I am following the guide for Plain PHP Upload

    I am getting 500 error for the fopen as the file size is large.

    I search the repo issues and try to use the readStream and writeStream method as suggested. But unfortunately, I am not able to find the correct solution.

    Any reference code example or other resources will be really helpful.

    Thanks a lot for such an amazing package. 😊

    Reviewed by hemratna at 2019-06-20 12:38
  • 5. Problem for big files - PHP Fatal error: Out of memory

    Hello,

    i m using flysystem but i can used it for files with 350 MO i have this error ,

    PHP Fatal error:  Out of memory (allocated 763101184) (tried to allocate 380559298 bytes) in /var/www/script/vendor/league/flysystem/src/Adapter/Zip.php on line 64
    
    Fatal error: Out of memory (allocated 763101184) (tried to allocate 380559298 bytes) in /var/www/script/vendor/league/flysystem/src/Adapter/Zip.php on line 64
    
    

    what i can do please :

    Reviewed by ghost at 2014-06-02 10:29
  • 6. [READY] Use Any Adapter As Cache

    I've added the ability to use any adapter to cache to. I haven't added any tests yet. Once I get your feedback, I can either close this (if you reject the idea), or modify it (if you want parts changed), then write tests.

    Useage case: I am reading files from dropbox, but don't want to have to cache them to memory. Now I can cache them to the disk using the local filesystem adapter as a cache.

    TODO:

    • [x] Add cache adapter
    • [x] Get the approval of @FrenkyNet
    • [x] Make adjustments
    • [x] Add documentation
    • [x] Add tests
    Reviewed by GrahamCampbell at 2014-02-16 16:51
  • 7. Problems with FTP adapter

    I'm trying to use this library to connect to a WS_FTP server. I encounter the same problem I had some time ago with the PHP FTP functions: directory listing, file getting/putting only work if filepaths are sent to the FTP connection with double quotes (") around.

    Reviewed by zupolgec at 2014-06-27 23:05
  • 8. Trying to access array offset on value of type bool

    Bug Report

    Error when using streams and S3 on php 7.4 Works fine on php 7.3 But breaks on php 7.4

    How to reproduce

    Upload a file to s3 using fopen

    Storage::disk('some-s3-disk');
    $disk->put('test.jpg', fopen($imageUrl, "r"));
    
    // Works fine
    // $disk->put('test.jpg', file_get_contents($mageUrl));
    
    php74
    Reviewed by bjora857 at 2019-12-29 14:04
  • 9. FTP ssl problem

    Hi,

    I am using Laravel 5.2 with the Storage adapter for connecting to a FTP server with SSL. I am getting this error and don't know why...

     [ErrorException]
      ftp_rawlist(): SSL read failed
    
    PHP Fatal error:  Uncaught ErrorException: fclose(): supplied resource is not a valid stream resource in /home/test/public_html/vendor/league/flysystem/src/Adapter/Ftp.php:495
    Stack trace:
    #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'fclose(): suppl...', '/home/test/...', 495, Array)
    #1 /home/test/public_html/vendor/league/flysystem/src/Adapter/Ftp.php(495): fclose(Resource id #209)
    #2 /home/test/public_html/vendor/league/flysystem/src/Adapter/Ftp.php(191): League\Flysystem\Adapter\Ftp->isConnected()
    #3 /home/test/public_html/vendor/league/flysystem/src/Adapter/AbstractFtpAdapter.php(609): League\Flysystem\Adapter\Ftp->disconnect()
    #4 [internal function]: League\Flysystem\Adapter\AbstractFtpAdapter->__destruct()
    #5 {main}
      thrown in /home/test/public_html/vendor/league/flysystem/src/Adapter/Ftp.php on line 495
    

    This is my config "config/filesystems.php":

    'ftp' => [
                'driver'   => 'ftp',
                'host'     => env('FTP_SERVER'),
                'port'     => env('FTP_PORT'),
                'username' => env('FTP_USERNAME'),
                'password' => env('FTP_PASSWORD'),
                'passive'  => true,
                'ssl'      => true,
                'timeout'  => 30,
                'root'     => '/',
            ],
    

    This is my code:

    Storage::disk('ftp')->allFiles();
    

    My config is correct and I tested it on 2 machines, both giving the same error... Before I used FuelPHP and never had any problems with FTP SSL...

    Reviewed by it-can at 2016-08-12 15:11
  • 10. Exception thrown by Local driver attempting to create directory in quick succession

    I have an application where I allow a user to pick multiple files for upload from a web form. These are then submitted individually and asynchronously using jQuery and HTML FormData.

    If I have several small files submitting at once, it is possible that the server arrives at Local::ensureDirectory() almost simultaneously and the if ( ! is_dir($root)) check returns an incorrect result.

    This can result in an ErrorException "mkdir(): File exists". I'm not sure you can reproduce the error without my app, but steps would be:

    • Laravel 5.2 app running on local Vagrant Homestead instance with PHP7
    • Multiple async submissions to a route which should result in creation of a directory that does not yet exist
    • Produces exception below:

    screen shot 2016-03-24 at 13 40 53

    This may well be a PHP problem and/or Vagrant not running fast enough in a local environment, but I wonder if it's possible to mitigate, perhaps wrapping in try/catch that looks for the "File exists" message? I've checked the Exception thrown for other problems such as permissions and unfortunately it's identical apart from the message - and I guess that may change in different languages.

    Reviewed by dmlogic at 2016-03-24 14:00
  • 11. Introduce a common exception for failed commands

    This is somewhat related to #611.

    If I try to write a file on S3 using Flysystem, and a connection problem occurs, I get an S3 exception:

    Aws\S3\Exception\S3Exception: Error executing "PutObject" on ...

    For Dropbox, I get a (subclass of) Dropbox\Exception.

    First of all, these adapters do not respect the AdapterInterface contract by allowing an exception to be thrown, instead of returning false on failure.

    Secondly, I would suggest throwing an exception in all cases when something goes wrong on the underlying storage. And to keep code portable (i.e. allowing to change the storage adapter at the flip of a switch), this exception should belong to the Flysystem package.

    At the moment, I have to do:

    try {
        $filesystem->write($path, $contents);
    } catch (S3Exception $e) {
        // ...
    }
    

    If I decide to switch to Dropbox, I have to search through my entire codebase for Flysystem calls, and update them to something like:

    try {
        $filesystem->write($path, $contents);
    } catch (Dropbox\Exception $e) {
        // ...
    }
    

    And if I'm writing an app that can accept any adapter, using information from a config file, I have to take all possible errors into account:

    try {
        $filesystem->write($path, $contents);
    } catch (S3Exception $e) {
        // ...
    } catch (Dropbox\Exception $e) {
        // ...
    }
    

    And so on, without forgetting any adapter. As you can see, this is not a very good practice.

    Introducing a common interface for these errors would allow us to call:

    try {
        $filesystem->write($path, $contents);
    } catch (AdapterException $e) {
        // ...
    }
    

    This way, there is no need to rewrite any code when switching to another adapter.

    As I understand the project in its current status, you decided to return false in some methods, when something goes wrong. The fact is, the few adapters I had a chance to look at do not respect this contract properly (S3 and Dropbox thrown their own exceptions, Ftp and Local raise PHP errors).

    There are two solutions to this problem:

    • Fix all the adapters to catch any exception or error (including PHP warnings for adapters relying on native functions) and return false where appropriate
    • Change the contract to never return false on methods such as write(), and throw an AdapterException on failure instead

    I would strongly suggest the second option, because it breaks the application flow when something goes wrong; otherwise an error could go unnoticed if the developer forgets to check the return value using something like:

    if (! $fs->write($path, $contents)) {
        ...
    }
    

    Plus, although returning false gives an opportunity to catch failures on operations such as write(), there is no such opportunity on methods that return boolean values, such as has().

    Having all of them throw an exception in case of a failure harmonizes the whole thing.

    Happily waiting for your feedback on this one. I could help rewrite the code if you agree with the idea!

    Reviewed by BenMorel at 2016-03-16 15:16
PHP library that provides a filesystem abstraction layer − will be a feast for your files!

Gaufrette Gaufrette provides a filesystem abstraction layer. Why use Gaufrette? Imagine you have to manage a lot of medias in a PHP project. Lets see

May 11, 2022
A Flysystem proxy adapter that enables compression and encryption of files and streams on the fly

Slam / flysystem-compress-and-encrypt-proxy Compress and Encrypt files and streams before saving them to the final Flysystem destination. Installation

Mar 10, 2022
Private file storage and share with user build with laravel and vue inspired by google drive
Private file storage and share with user build with laravel and vue inspired by google drive

LaravelDrive is a file storage system that allows store private file and share with users build wiht laravel and vue inspired by google drive. Laravel

May 17, 2022
Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel.
Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel.

Laravel Flysystem Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel. It utilises my Larave

Feb 4, 2022
Detects file type by filename or content and generates correct mimetype.

FileTypeDetector Files type detector based on file name extension or file content (binary content). Usage Installation Supported formats Usage File Ty

Apr 18, 2022
Uguu is a simple lightweight temporary file host with support for drop, paste, click and API uploading.

Uguu What is Uguu? Uguu is a simple lightweight temporary file hosting and sharing platform, but can also be used as a permanent file host. Features O

May 26, 2022
A PHP library to deal with all those media services around, parsing their URLs and displaying their audios/videos.

MediaEmbed A utility library that generates HTML embed tags for audio or video located on a given URL. It also parses and validates given media URLs.

Jan 12, 2022
This small PHP package assists in the loading and parsing of VTT files.

VTT Transcriptions This small PHP package assists in the loading and parsing of VTT files. Usage use Laracasts\Transcriptions\Transcription; $transcr

May 27, 2022
Basic anonymous and registered upload storage for temporary share file self hosted.
 Basic anonymous and registered upload storage for temporary share file self hosted.

TMPShareX Basic anonymous and registered upload storage for temporary share file self hosted. Server Requirement PHP 7.4.8 [Support PHP 8] Nginx 1.19.

Feb 3, 2022
Oxygen Builder's better workflow and environment

Oxygen Builder's better workflow and environment Built with ❤️ Official Website | Documentation | Change Log Supporting Artifact is an open source pro

Mar 27, 2022
Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.

Documents ・ Installation ・ Integration ・ Config ・ Customization ・ Events ・ Upgrade ・ Demo ・ FAQ Features File upload and management Uploading validati

May 26, 2022
A lightweight file manager with full ShareX, Screencloud support and more
A lightweight file manager with full ShareX, Screencloud support and more

XBackBone is a simple, self-hosted, lightweight PHP file manager that support the instant sharing tool ShareX and *NIX systems. It supports uploading

May 18, 2022
PictShare is an open source image, mp4, pastebin hosting service with a simple resizing and upload API that you can host yourself.
PictShare is an open source image, mp4, pastebin hosting service with a simple resizing and upload API that you can host yourself.

PictShare is an open source image, mp4, pastebin hosting service with a simple resizing and upload API that you can host yourself.

May 17, 2022
Pomf is a simple lightweight file host with support for drop, paste, click and API uploading.

Pomf Pomf is a simple file uploading and sharing platform. Features One click uploading, no registration required A minimal, modern web interface Drag

May 23, 2022
FileGator - a free, open-source, self-hosted web application for managing files and folders.
FileGator - a free, open-source, self-hosted web application for managing files and folders.

FileGator - Powerful Multi-User File Manager FileGator is a free, open-source, self-hosted web application for managing files and folders. You can man

May 22, 2022
Abstraction for local and remote filesystems

League\Flysystem About Flysystem Flysystem is a file storage library for PHP. It provides one interface to interact with many types of filesystems. Wh

Apr 22, 2021
Provides a unified interface to local and remote authentication systems.

Aura.Auth Provides authentication functionality and session tracking using various adapters; currently supported adapters are: Apache htpasswd files S

Jan 27, 2022
A simple PHP web backdoor allows you to retrieve directory/file contents and upload file(s) from the local machine or remote URL.
A simple PHP web backdoor allows you to retrieve directory/file contents and upload file(s) from the local machine or remote URL.

Simple PHP Web Backdoor A simple PHP web backdoor allows you to retrieve directory/file contents and upload file(s) from the local machine or remote U

May 12, 2022