PHPackages                             kompas/flysystem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. kompas/flysystem

ActiveLibrary[File &amp; Storage](/categories/file-storage)

kompas/flysystem
================

Filesystem abstraction, but easy.

0.4.1(12y ago)0591MITPHP

Since Oct 28Pushed 12y ago2 watchersCompare

[ Source](https://github.com/kompascom/flysystem)[ Packagist](https://packagist.org/packages/kompas/flysystem)[ RSS](/packages/kompas-flysystem/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (9)Versions (47)Used By (0)

Flysystem by [@frankdejonge](http://twitter.com/frankdejonge)
=============================================================

[](#flysystem-by-frankdejonge)

[![Build Status](https://camo.githubusercontent.com/451de63193516e96631623fd5251cc17640f8b76e9d01ae21a32ee213f57d227/68747470733a2f2f7472617669732d63692e6f72672f7468657068706c65616775652f666c7973797374656d2e706e67)](https://travis-ci.org/thephpleague/flysystem)[![Latest Stable Version](https://camo.githubusercontent.com/8ea8e82836d113f9257d36aa0ee2eada85d8633aed71425ed9c7f27311be343a/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f666c7973797374656d2f762f737461626c652e706e67)](https://packagist.org/packages/league/flysystem)[![Total Downloads](https://camo.githubusercontent.com/c5e20e09aeec833346d36afe3209286b23bf40562017c9358e2050b61a6dd1f4/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f666c7973797374656d2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/league/flysystem) [![License](https://camo.githubusercontent.com/878309e10e91f08c6ef6b30e86bd1900b7353730ed99ff796352d763f94d2ce3/68747470733a2f2f706f7365722e707567782e6f72672f6c65616775652f666c7973797374656d2f6c6963656e73652e706e67)](https://packagist.org/packages/league/flysystem)[![SensioLabsInsight](https://camo.githubusercontent.com/6f94cc5313e7a7e48501169bb89727e0ce43c6a200392f769117672501f9be23/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f39383230663161662d326664302d346162362d623432612d3033653063383231653061662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/9820f1af-2fd0-4ab6-b42a-03e0c821e0af)[![Coverage Status](https://camo.githubusercontent.com/457876c3bc3e42637db851853cbabc7cd70947ff0fcdcb9448f5a89b3f5dca95/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7468657068706c65616775652f666c7973797374656d2f62616467652e706e67)](https://coveralls.io/r/thephpleague/flysystem)

Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one.

[Flysystem on Packagist](https://packagist.org/packages/league/flysystem)

Support Flysystem
=================

[](#support-flysystem)

Do you use Flysystem often? Supporting it through Gittip will help freeing up extra time for me to work on bugs, new features and documentation.

[![Support with Gittip](https://camo.githubusercontent.com/f2d16f5a8d7291c25de8839f68f0fc7fc132750616a31281646b8795a3b824b4/687474703a2f2f696d672e736869656c64732e696f2f6769747469702f4672656e6b794e65742e737667)](https://www.gittip.com/FrenkyNet/)

Goals
=====

[](#goals)

- Have a generic API for handling common tasks across multiple file storage engines.
- Have consistent output which you can rely on.
- Integrate well with other packages/frameworks.
- Be cacheable.
- Emulate directories in systems that support none, like AwsS3.
- Support third party plugins.
- Make it easy to test your filesystem interactions.
- Support streams for bigger file handling

Installation
============

[](#installation)

Through Composer, obviously:

```
{
    "require": {
        "league/flysystem": "0.4.*"
    }
}
```

You can also use Flysystem without using Composer by registering an autoloader function:

```
spl_autoload_register(function($class) {
    if (!substr($class, 0, 17) === 'League\\Flysystem') {
        return;
    }

    $location = __DIR__ . 'path/to/flysystem/src/' . str_replace('\\', '/', $class) . '.php';

    if (is_file($location)) {
        require_once($location);
    }
});
```

Adapters
--------

[](#adapters)

- Local
- Amazon Web Services - S3
- Rackspace Cloud Files
- Dropbox
- Ftp
- Sftp (through phpseclib)
- Zip (through ZipArchive)
- WebDAV (through SabreDAV)
- NullAdapter

### Planned Adapters

[](#planned-adapters)

- Azure
- PR's welcome?

Caching
-------

[](#caching)

- Memory (array caching)
- Redis (through Predis)
- Memcached
- Adapter

Local Setup
-----------

[](#local-setup)

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;

$filesystem = new Filesystem(new Adapter(__DIR__.'/path/to/root'));
```

Zip Archive Setup
-----------------

[](#zip-archive-setup)

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Zip as Adapter;

$filesystem = new Filesystem(new Adapter(__DIR__.'/path/to/archive.zip'));
```

AWS S3 Setup
------------

[](#aws-s3-setup)

```
use Aws\S3\S3Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\AwsS3 as Adapter;

$client = S3Client::factory(array(
    'key'    => '[your key]',
    'secret' => '[your secret]',
));

$filesystem = new Filesystem(new Adapter($client, 'bucket-name', 'optional-prefix'));
```

Rackspace Setup
---------------

[](#rackspace-setup)

```
use OpenCloud\OpenStack;
use OpenCloud\Rackspace;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Rackspace as Adapter;

$client = new OpenStack(Rackspace::UK_IDENTITY_ENDPOINT, array(
    'username' => ':username',
    'password' => ':password',
));

$store = $client->objectStoreService('cloudFiles', 'LON');
$container = $store->getContainer('flysystem');

$filesystem = new Filesystem(new Adapter($container));
```

You can also use a prefix to "namespace" your filesystem.

```
$filesystem = new Filesystem(new Adapter\Rackspace($container, 'prefix'));
```

Dropbox Setup
-------------

[](#dropbox-setup)

```
use Dropbox\Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Dropbox as Adapter;

$client = new Client($token, $appName);
$filesystem = new Filesystem(new Adapter($client, 'optional/path/prefix'));
```

FTP Setup
---------

[](#ftp-setup)

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Ftp as Adapter;

$filesystem = new Filesystem(new Adapter(array(
    'host' => 'ftp.example.com',
    'username' => 'username',
    'password' => 'password',

    /** optional config settings */
    'port' => 21,
    'root' => '/path/to/root',
    'passive' => true,
    'ssl' => true,
    'timeout' => 30,
)));
```

SFTP Setup
----------

[](#sftp-setup)

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Sftp as Adapter;

$filesystem = new Filesystem(new Adapter(array(
    'host' => 'example.com',
    'port' => 21,
    'username' => 'username',
    'password' => 'password',
    'privateKey' => 'path/to/or/contents/of/privatekey',
    'root' => '/path/to/root',
    'timeout' => 10,
)));
```

WebDAV Setup
------------

[](#webdav-setup)

```
$client = new Sabre\DAV\Client($settings);
$adapter = new League\Flysystem\Adapter\WebDav($client);
$flysystem = new League\Flysystem\Filesystem($adapter);
```

NullAdapter Setup
-----------------

[](#nulladapter-setup)

This adapter acts like /dev/null, you can only write to it. Reading from it is never possible.

```
$adapter = new League\Flysystem\Adapter\NullAdapter;
$flysystem = new League\Flysystem\Filesystem($adapter);
```

Predis Caching Setup
--------------------

[](#predis-caching-setup)

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Cache\Predis as Cache;

$filesystem = new Filesystem(new Adapter(__DIR__.'/path/to/root'), new Cache);

// Or supply a client
$client = new Predis\Client;
$filesystem = new Filesystem(new Adapter(__DIR__.'/path/to/root'), new Cache($client));
```

Memcached Caching Setup
-----------------------

[](#memcached-caching-setup)

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Cache\Memcached as Cache;

$memcached = new Memcached;
$memcached->addServer('localhost', 11211);

$filesystem = new Filesystem(new Adapter(__DIR__.'/path/to/root'), new Cache($memcached, 'storageKey', 300));
// Storage Key and expire time are optional
```

Adapter Caching Setup
---------------------

[](#adapter-caching-setup)

```
use Dropbox\Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Dropbox;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Cache\Adapter;

$client = new Client('token', 'app');
$dropbox = new Dropbox($client, 'prefix');

$local = new Local('path');
$cache = new Adapter($local, 'file', 300);
// Expire time is optional

$filesystem = new Filesystem($dropbox, $cache);
```

General Usage
-------------

[](#general-usage)

**Write Files**

```
$filesystem->write('filename.txt', 'contents');
```

**Update Files**

```
$filesystem->update('filename.txt', 'new contents');
```

**Write or Update Files**

```
$filesystem->put('filename.txt', 'contents');
```

**Read Files**

```
$contents = $filesystem->read('filename.txt');
```

**Check if a file exists**

```
$exists = $filesystem->has('filename.txt');
```

**Delete Files**

```
$filesystem->delete('filename.txt');
```

**Rename Files**

```
$filesystem->rename('filename.txt', 'newname.txt');
```

**Get Mimetypes**

```
$mimetype = $filesystem->getMimetype('filename.txt');
```

**Get Timestamps**

```
$timestamp = $filesystem->getTimestamp('filename.txt');
```

**Get File Sizes**

```
$size = $filesystem->getSize('filename.txt');
```

**Create Directories**

```
$filesystem->createDir('nested/directory');
```

Directories are also made implicitly when writing to a deeper path

```
$filesystem->write('path/to/filename.txt', 'contents');
```

**Delete Directories**

```
$filesystem->deleteDir('path/to/directory');
```

**Manage Visibility**

Visibility is the abstraction of file permissions across multiple platforms. Visibility can be either public or private.

```
use League\Flysystem\AdapterInterface;
$filesystem->write('db.backup', $backup, [
    'visibility' => AdapterInterface::VISIBILITY_PRIVATE),
]);
// or simply
$filesystem->write('db.backup', $backup, ['visibility' => 'private']);
```

You can also change and check visibility of existing files

```
if ($filesystem->getVisibility('secret.txt') === 'private') {
    $filesystem->setVisibility('secret.txt', 'public');
}
```

Global visibility setting
-------------------------

[](#global-visibility-setting)

You can set the visibility as a default, which prevents you from setting it all over the place.

```
$filesystem = new League\Flysystem\Filesystem($adapter, $cache, [
    'visibility' => AdapterInterface::VISIBILITY_PRIVATE
]);
```

***List Contents***

```
$contents = $filemanager->listContents();
```

The result of a contents listing is a collection of arrays containing all the metadata the file manager knows at that time. By default a you'll receive path info and file type. Additional info could be supplied by default depending on the adapter used.

Example:

```
foreach ($contents as $object) {
    echo $object['basename'].' is located at'.$object['path'].' and is a '.$object['type'];
}
```

By default Flysystem lists the top directory non-recursively. You can supply a directory name and recursive boolean to get more precise results

```
$contents = $flysystem->listContents('some/dir', true);
```

***List paths***

```
$paths = $filemanager->listPaths();

foreach ($paths as $path) {
    echo $path;
}
```

***List with ensured presence of specific metadata***

```
$listing = $flysystem->listWith(['mimetype', 'size', 'timestamp'], 'optional/path/to/dir', true);

foreach ($listing as $object) {
    echo $object['path'].' has mimetype: '.$object['mimetype'];
}
```

***Get file into with explicit metadata***

```
$info = $flysystem->getWithMetadata('path/to/file.txt', ['timestamp', 'mimetype']);
echo $info['mimetype'];
echo $info['timestamp'];
```

Using streams for reads and writes
----------------------------------

[](#using-streams-for-reads-and-writes)

```
$stream = fopen('/path/to/database.backup', 'r+');
$flysystem->writeStream('backups/' . strftime('%G-%m-%d') . '.backup', $stream);

// Using write you can also directly set the visibility
$flysystem->writeStream('backups/' . strftime('%G-%m-%d') . '.backup', $stream, 'private');

// Or update a file with stream contents
$flysystem->updateStream('backups/' . strftime('%G-%m-%d') . '.backup', $stream);

// Retrieve a read-stream
$stream = $flysystem->readStream('something/is/here.ext');
$contents = stream_get_contents($stream);
fclose($stream);

// Create or overwrite using a stream.
$putStream = tmpfile();
fwrite($putStream, $contents);
rewind($putStream);
$filesystem->putStream('somewhere/here.txt', $putStream);
fclose($putStream);
```

S3 and writeStream
------------------

[](#s3-and-writestream)

In order to get the correct mime type for the object, supply it like so:

```
$s3->writeStream('path/to/object.png', $stream, [
    'visibility' => 'public',
    'mimetype' => 'image/png',
]);
```

Plugins
-------

[](#plugins)

Need a feature which is not included in Flysystem's bag of tricks? Write a plugin!

```
use League\Flysystem\FilesystemInterface;
use League\Flysystem\PluginInterface;

class MaximusAwesomeness implements PluginInterface
{
    protected $filesystem;

    public function setFilesystem(FilesystemInterface $filesystem)
    {
        $this->filesystem = $filesystem;
    }

    public function getMethod()
    {
        return 'getDown';
    }

    public function handle($path = null)
    {
        $contents = $this->filesystem->read($path);

        return sha1($contents);
    }
}
```

Now we're ready to use the plugin

```
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter;

$filesystem = new Filesystem(new Adapter\Local(__DIR__.'/path/to/files/'));
$filesystem->addPlugin(new MaximusAwesomeness);
$sha1 = $filesystem->getDown('path/to/file');
```

Mount Manager
=============

[](#mount-manager)

Flysystem comes with an wrapper class to easily work with multiple filesystem instances from a single object. The `Flysystem\MountManager` is an easy to use container allowing you do simplify complex cross-filesystem interactions.

Setting up a Mount Manager is easy:

```
$ftp = new League\Flysystem\Filesystem($ftpAdapter);
$s3 = new League\Flysystem\Filesystem($s3Adapter);
$local = new League\Flysystem\Filesystem($localAdapter);

// Add them in the constructor
$manager = new League\Flysystem\MountManager(array(
    'ftp' => $ftp,
    's3' => $s3,
));

// Or mount them later
$manager->mountFilesystem('local', $local);
```

Now we do all the file operations we'd normally do on a `Flysystem\Filesystem` instance.

```
// Read from FTP
$contents = $manager->read('ftp://some/file.txt');

// And write to local
$manager->write('local://put/it/here.txt', $contents);
```

This makes it easy to code up simple sync strategies.

```
$contents = $manager->listContents('local://uploads', true);

foreach ($contents as $entry) {
    $update = false;

    if ( ! $manager->has('storage://'.$entry['path'])) {
        $update = true;
    }

    elseif ($manager->getTimestamp('local://'.$entry['path']) > $manager->getTimestamp('storage://'.$entry['path'])) {
        $update = true;
    }

    if ($update) {
        $manager->put('storage://'.$entry['path'], $manager->read('local://'.$entry['path']));
    }
}
```

Enjoy.
======

[](#enjoy)

Oh and if you've come down this far, you might as well follow me on [twitter](http://twitter.com/frankdejonge).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 83.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

45

Last Release

4406d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3264535342f6dd2bacce6425cb96c32d6113e25e3adac91a11660be332e764eb?d=identicon)[fahmiardi](/maintainers/fahmiardi)

---

Top Contributors

[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (274 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (17 commits)")[![4d47](https://avatars.githubusercontent.com/u/729919?v=4)](https://github.com/4d47 "4d47 (5 commits)")[![jeroenvdgulik](https://avatars.githubusercontent.com/u/242090?v=4)](https://github.com/jeroenvdgulik "jeroenvdgulik (4 commits)")[![hassankhan](https://avatars.githubusercontent.com/u/1781985?v=4)](https://github.com/hassankhan "hassankhan (4 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (4 commits)")[![turneliusz](https://avatars.githubusercontent.com/u/624797?v=4)](https://github.com/turneliusz "turneliusz (3 commits)")[![fahmiardi](https://avatars.githubusercontent.com/u/1201482?v=4)](https://github.com/fahmiardi "fahmiardi (3 commits)")[![pborreli](https://avatars.githubusercontent.com/u/77759?v=4)](https://github.com/pborreli "pborreli (2 commits)")[![dmyers](https://avatars.githubusercontent.com/u/207171?v=4)](https://github.com/dmyers "dmyers (2 commits)")[![mitchellvanw](https://avatars.githubusercontent.com/u/3061428?v=4)](https://github.com/mitchellvanw "mitchellvanw (1 commits)")[![MrHash](https://avatars.githubusercontent.com/u/390925?v=4)](https://github.com/MrHash "MrHash (1 commits)")[![Purus](https://avatars.githubusercontent.com/u/1077735?v=4)](https://github.com/Purus "Purus (1 commits)")[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (1 commits)")[![tom-1bg](https://avatars.githubusercontent.com/u/11245840?v=4)](https://github.com/tom-1bg "tom-1bg (1 commits)")[![gimler](https://avatars.githubusercontent.com/u/200904?v=4)](https://github.com/gimler "gimler (1 commits)")[![jeffreyroberts](https://avatars.githubusercontent.com/u/2320614?v=4)](https://github.com/jeffreyroberts "jeffreyroberts (1 commits)")[![brunogaspar](https://avatars.githubusercontent.com/u/2285372?v=4)](https://github.com/brunogaspar "brunogaspar (1 commits)")[![judgej](https://avatars.githubusercontent.com/u/395934?v=4)](https://github.com/judgej "judgej (1 commits)")

---

Tags

ftpfilesystems3awssftpWebDAVremotedropbox

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kompas-flysystem/health.svg)

```
[![Health](https://phpackages.com/badges/kompas-flysystem/health.svg)](https://phpackages.com/packages/kompas-flysystem)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[innoge/laravel-rclone

A sleek PHP wrapper around rclone with Laravel-style fluent API syntax

174.1k](/packages/innoge-laravel-rclone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
