PHPackages                             phossa2/storage - 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. phossa2/storage

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

phossa2/storage
===============

A storage front for local or remote storage system

2.0.1(9y ago)21432MITPHPPHP ~5.4|~7.0

Since Aug 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/phossa2/storage)[ Packagist](https://packagist.org/packages/phossa2/storage)[ Docs](https://github.com/phossa2/storage)[ RSS](/packages/phossa2-storage/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (2)

phossa2/storage
===============

[](#phossa2storage)

[![Build Status](https://camo.githubusercontent.com/299c9a6cc37c9ae2c22e6a91b5d3fa98abb120b087662cc528c0b7dfc41a9aa9/68747470733a2f2f7472617669732d63692e6f72672f70686f737361322f73746f726167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa2/storage)[![Code Quality](https://camo.githubusercontent.com/8f08312882bd803aedfafbba824f0a8f27d93c6773154c4395d73dea9175690d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f737361322f73746f726167652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phossa2/storage/)[![Code Climate](https://camo.githubusercontent.com/79db5badf44727eb3329a969229a965990187a2bf4a7f3d97bb6d2231d500640/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f737361322f73746f726167652f6261646765732f6770612e737667)](https://codeclimate.com/github/phossa2/storage)[![PHP 7 ready](https://camo.githubusercontent.com/2fad9365c89004ee07f446e55fa0eebdf7c8168434d1aac05a82ff4023a46291/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f70686f737361322f73746f726167652f6d61737465722f62616467652e737667)](https://travis-ci.org/phossa2/storage)[![HHVM](https://camo.githubusercontent.com/8a04a10e80a493399adb6eaea0efba737dff934c0e80007d28f0657c2e3ca4d1/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f737361322f73746f726167652e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa2/storage)[![Latest Stable Version](https://camo.githubusercontent.com/05cf858f01b23abef23c8248167b1297a7c38194f99dc3317014092074ae1d44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f737361322f73746f726167652e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa2/storage)[![License](https://camo.githubusercontent.com/4fc6538ded72843e26a272d300ce4c95da083ce92576e10e4fdd505d579a8125/68747470733a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://mit-license.org/)

**phossa2/storage** is a PHP storage library with support for local or cloud storage.

It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2: Coding Style Guide"), [PSR-3](http://www.php-fig.org/psr/psr-3/ "PSR-3: Logger Interface"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader"), and the proposed [PSR-5](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md "PSR-5: PHPDoc").

Installation
------------

[](#installation)

Install via the `composer` utility.

```
composer require "phossa2/storage"
```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phossa2/storage": "2.*"
    }
}
```

Introduction
------------

[](#introduction)

- Simple [restful like APIs](#api).
- [Unified path syntax](#unified) like `/local/img/avatar.jpg` for all systems.
- Mounting and umounting [`filesystem`](#filesystem).
- Support for different [drivers](#driver).
- Support for [stream](#stream).

Usage
-----

[](#usage)

Create the storage instance,

```
use Phossa2\Storage\Storage;
use Phossa2\Storage\Filesystem;
use Phossa2\Storage\Driver\LocalDriver;

// mount local dir '/www/storage' to '/local'
$storage = new Storage(
    '/local',
    new Filesystem('/www/storage')
);

// add a file
$filename = '/local/newfile.txt';
$storage->put($filename, 'this is the content');

// check existens
if ($storage->has($filename)) {
    // read file content
    $str = $storage->get($filename);

    // delete the file
    $storage->del($filename);
}

// mount another filesystem
$storage->mount('/aws', new Filesystem(new AwsDriver()));
```

Features
--------

[](#features)

- **Restful APIs**

    Support for simple and instinctive APIs like `get()`, `put()`, `has()` and `del()` etc.

    Others APIs like

    - `meta()`

        Get the meta data of the file

        ```
        // get the meta data
        if ($storage->has($file)) {
            $meta = $storage->meta($file);
        }

        // update meta data
        $new = ['mtime' => time()];
        $storage->put($file, null, $new);
        ```
    - `copy()` and `move()`

        Copy or move files in or between filesystems

        ```
        // move to another name
        $storage->move('/local/README.txt', '/local/README.bak.txt');

        // copy into another filesystem's directory
        $storage->copy('/local/README.txt', '/aws/www/');
        ```
- **Unified path syntax**

    Uses unified path syntax like `/local/dir/file.txt' for all systems including windows. The underlying driver is responsible for translating path transparently.

    ```
    $storage = new Storage(
      '/disk/d',
      new Filesystem(new LocalDriver('D:\\\\'))
    );

    $storage->put('/disk/d/temp/newfile.txt', 'this is content');
    ```
- **Mounting and umounting filesystems**

    `filesytem` is a wrapper of different drivers with permissions. User may mount a read only filesystem as follows,

    ```
    // mount as readonly, default is Filesystem::PERM_ALL
    $storage->mount(
        '/readonly',
        new Filesystem(
          '/home/www/public',
          Filesystem::PERM_READ
        )
    );

    // will fail
    $storage->put('/readonly/newfile.txt', 'this is the content');
    ```

    Different filesystem may use same driver,

    ```
    $driver = new LocalDriver('/home/www/public');

    // writable
    $storage->mount('/public', new Filesystem($driver));

    // readonly
    $storage->mount('/readonly', new Filesystem($driver, Filesystem::PERM_READ));
    ```

    Filesystems may overlapping on top of others,

    ```
    // mount root
    $storage->mount('/', new Filesystem(...));

    // mount var
    $storage->mount('/var', new Filesystem(...));

    // mount cache
    $storage->mount('/var/cache', new Filesystem(...));
    ```
- **Drivers**

    Support for different drivers inlucing local or cloud storage.
- **Streaming**

    Write and read streams as follows,

    ```
    // read stream
    $stream = $storage->get('/local/thefile.txt', true);

    // write with stream
    $storage->put('/local/anotherfile.txt', $stream);

    // close it
    if (is_resource($stream)) {
        fclose($stream);
    }
    ```

APIs
----

[](#apis)

- `\Phossa2\Storage\Storage`

    - `bool has(string $path)`

        check `$path` existens.
    - `null|string|array|resource get(string $path, bool $getAsStream)`

        Get content of the `$path`.

        - If not found or failure, returns `NULL`.
        - If `$path` is a directory, returns an array of the full paths of the files under this `$path`.
        - If `$getAsStream` is `true`, returns a stream handler.
    - `bool put(string $path, string|resource|null $content, array $meta = [])`

        Set the content or meta data of the `$path`.
    - `bool del(string $path)`

        Remove the `$path`. If `$path` is a directory, will remove all files under this path and the path itself (unless it is a mount point).
    - `bool copy(string $from, string $to)` and `bool copy(string $from, string $to)`

        Copy or move `$from` to `$to`.
    - `array meta(string $path)`

        Get the meta data of `$path`. If not found or error, returns `[]`.
    - `Phossa2\Storage\Path path(string $path)`

        Returns a `Phossa2\Storage\Path` object
- Error related

    - `bool hasError()`

        Has error ?
    - `string getError()`

        Get previous error message. If no error, returns `''`.

        ```
        if (!$storage->copy('/local/from.txt', '/local/to.txt')) {
            $err = $storage->getError();
        }
        ```
    - `string getErrorCode()`

        Get a numeric string of the error code.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) from more information.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTE](CONTRIBUTE.md) for more information.

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa2/shared &gt;= 2.0.23

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.5% 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 ~11 days

Total

2

Last Release

3591d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19922046?v=4)[Hong Zhang](/maintainers/phossa2)[@phossa2](https://github.com/phossa2)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (39 commits)")[![phossa2](https://avatars.githubusercontent.com/u/19922046?v=4)](https://github.com/phossa2 "phossa2 (1 commits)")

---

Tags

storagephossa

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phossa2-storage/health.svg)

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

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k665.7M2.4k](/packages/league-flysystem)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k277.8M959](/packages/league-flysystem-aws-s3-v3)[google/cloud

Google Cloud Client Library

1.2k16.5M57](/packages/google-cloud)[qiniu/php-sdk

Qiniu Resource (Cloud) Storage SDK for PHP

8093.0M247](/packages/qiniu-php-sdk)[sylius/resource-bundle

Resource component for Sylius.

23610.6M211](/packages/sylius-resource-bundle)[microsoft/azure-storage-blob

This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage Blob APIs.

5516.8M70](/packages/microsoft-azure-storage-blob)

PHPackages © 2026

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