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

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

phpbook/storage
===============

PHP Storage Library For AWSS3, FTP, LOCAL

1.2.5(5y ago)2581MITPHPPHP &gt;=7.1.0

Since Jun 14Pushed 5y agoCompare

[ Source](https://github.com/phpbook-sources/storage)[ Packagist](https://packagist.org/packages/phpbook/storage)[ Docs](https://github.com/phpbook-sources/storage)[ RSS](/packages/phpbook-storage/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)DependenciesVersions (18)Used By (1)

- [About Storage](#about-storage)
- [Composer Install](#composer-install)
- [Declare Configurations](#declare-configurations)
- [Manager](#manager)
- [Validation](#validation)
- [Parse](#parse)
- [File Stage](#file-stage)

### About Storage

[](#about-storage)

- A lightweight storage PHP library available for AWSS3, FTP, LOCAL.
- Requires PHP Extension FINFO.

### Composer Install

[](#composer-install)

```
composer require phpbook/storage

```

### Declare Configurations

[](#declare-configurations)

```
/********************************************
 *
 *  Declare Configurations
 *
 * ******************************************/

//Driver connection AWSS3

\PHPBook\Storage\Configuration\Storage::setConnection('backups',
	(new \PHPBook\Storage\Configuration\Connection)
		->setName('Backups')
		->setExceptionCatcher(function(String $message) {
			//the PHPBook Storage does not throw exceptions, but you can take it here
			//you can store $message in database or something else
		})
		->setDriver((new \PHPBook\Storage\Driver\AWSS3)
			->setKey('key')
			->setSecret('secret')
			->setRegion('region')
			->setBucket('bucket'))
);

//Driver connection FTP

\PHPBook\Storage\Configuration\Storage::setConnection('other',
	(new \PHPBook\Storage\Configuration\Connection)
		->setName('Other')
		->setExceptionCatcher(function(String $message) {
			//the PHPBook Storage does not throw exceptions, but you can take it here
			//you can store $message in database or something else
		})
		->setDriver((new \PHPBook\Storage\Driver\FTP)
			->setHost('host')
			->setPort(21)
			->setDirectory('ftp/root/path')
			->setUser('user')
			->setPassword('password'))
);

//Driver connection LOCAL

\PHPBook\Storage\Configuration\Storage::setConnection('main',
	(new \PHPBook\Storage\Configuration\Connection)
		->setName('Main')
		->setExceptionCatcher(function(String $message) {
			//the PHPBook Storage does not throw exceptions, but you can take it here
			//you can store $message in database or something else
		})
		->setDriver((new \PHPBook\Storage\Driver\LOCAL)
			->setDirectory('local/root/path'))
);

//Set default connection by connection alias

\PHPBook\Storage\Configuration\Storage::setDefault('main');

//Getting connections

$connections = \PHPBook\Storage\Configuration\Storage::getConnections();

foreach($connections as $code => $connection) {

	$connection->getName();

	$connection->getDriver();

};

?>
```

### Manager

[](#manager)

```
	//Connection code is not required if you set default connection

	// get file
	$contents = (new \PHPBook\Storage\Storage)
			->setConnectionCode('other')
			->setFile('path/in/storage/to/file/file.jpeg')
			->get();

	if ($contents) {
		//contents not null
	};

	// write and overwrite file, auto create missing directories
	$boolean = (new \PHPBook\Storage\Storage)
			->setFile('path/in/storage/to/file/file.jpeg')
			->write($contents);

	if ($boolean) {
		//done
	};

	// write and overwrite file from local file path, auto create missing directories
	$boolean = (new \PHPBook\Storage\Storage)
			->setFile('path/in/storage/to/file/file.jpeg')
			->write(\PHPBook\Storage\Local::getContents('absolute/local/file/path'));

	if ($boolean) {
		//done
	};

	// move file, auto create missing directories
	$boolean = (new \PHPBook\Storage\Storage)
			->setFile('path/in/storage/to/file/file.jpeg')
			->move('path/in/storage/to/file/file-rename.jpeg');

	if ($boolean) {
		//done
	};

	// delete file
	$boolean = (new \PHPBook\Storage\Storage)
			->setConnectionCode('other')
			->setFile('path/in/storage/to/file/file-rename.jpeg')
			->delete();

	if ($boolean) {
		//done
	};

	// get directory file names array
	$contents = (new \PHPBook\Storage\Directory)
			->setConnectionCode('other')
			->setDirectory('path/in/storage/to/get/file/names/array')
			->files();

	if ($contents) {
		//contents not null
	};

	// write directory, auto create missing parents directories
	$boolean = (new \PHPBook\Storage\Directory)
			->setDirectory('path/in/storage/to/files')
			->write();

	if ($boolean) {
		//done
	};

	// move directory, auto create missing parents directories
	$boolean = (new \PHPBook\Storage\Directory)
			->setDirectory('path/in/storage/to/files')
			->move('new/path/in/storage/to/files');

	if ($boolean) {
		//done
	};

	// delete directory and all its contents recursively
	$boolean = (new \PHPBook\Storage\Directory)
			->setDirectory('path/in/storage/to/files')
			->delete();

	if ($boolean) {
		//done
	};
```

### Validation

[](#validation)

```
	$contents = 'file-buffer-contents';

	$mimes = ['image']; //or ['image/jpeg', 'image/png']

	$sizeKiloBytes = 150;

	if (\PHPBook\Storage\Validation::isInMimeTypes($contents, $mimes)) {
		//file is ok
	};

	if (\PHPBook\Storage\Validation::isInLimitsKilobytes($contents, $sizeKiloBytes)) {
		//file is ok
	};
```

### Parse

[](#parse)

```
	//getting string contents to objects

	$item = \PHPBook\Storage\Parse::getByJson($stringJson);

	$item = \PHPBook\Storage\Parse::getByXml($stringXML);
```

### File Stage

[](#file-stage)

```
// you can create a file stage to upload a file, clear the current file or simply keep the file data untouch

	/* default file schema */
	$fileName = 'my-file.jpeg';
	$filePath = 'my/file/path';
	$connectionCode = 'my-connection-code'; //for default, use null or suppress the parameter

	/* Uploads a file */
	$statement = 'binary'; //binary contents to upload
	$fileStage = new \PHPBook\Storage\FileStage($statement, $fileName, $filePath, $connectionCode);

	/* Clear a file if exists */
	$statement = \PHPBook\Storage\FileStage::$Stage_Clear; //statement to clear the current file if exists
	$fileStage = new \PHPBook\Storage\FileStage($statement, $fileName, $filePath, $connectionCode);

	/* Keep a file untouch or without file */
	$statement = \PHPBook\Storage\FileStage::$Stage_Keep; //statement to keep the current file or keep without file
	$fileStage = new \PHPBook\Storage\FileStage($statement, $fileName, $filePath, $connectionCode);

	/* Prepare a statement string or binary content that is encoded */
	$statement = \PHPBook\Storage\FileStage::GetStatementOrBinaryDecoded('statement or encoded binary'); //returns the statement string or binary content decoded
	$fileStage = new \PHPBook\Storage\FileStage($statement, $fileName, $filePath, $connectionCode);

	/* Get file statement */
	$fileName = $fileStage->statement();

	/* After stage the file changes, you can persist, returns true or false to the operation */
	/* When is upload the binary contents, the phpbook uploads the file */
	/* When is stage clear, the phpbook clear the file */
	/* When is stage keep, nothing changes */
	$boolean = $fileStage->persist();

	/* If you need, you can get the file stage contents. */
	/* When is upload the binary, the phpbook retrieves the stage binary contents or null. */
	/* When is stage clear, the phpbook retrieves null. */
	/* When is stage keep, the phpbook retrieves the current file if exists otherwise returns null. */
	$contents = $fileStage->contents();

	/* Get file mime */
	/* When is upload the binary, the phpbook retrieves the mime binary contents or null. */
	/* When is stage clear, the phpbook retrieves null. */
	/* When is stage keep, the phpbook retrieves the current file mime if exists otherwise returns null. */
	$mime = $fileStage->mime();

	/* Get file hash */
	/* When is upload the binary, the phpbook retrieves the hash binary contents. */
	/* When is stage clear, the phpbook retrieves null. */
	/* When is stage keep, the phpbook retrieves the current file hash if exists otherwise returns null. */
	$mime = $fileStage->hash();

	/* Get file mime */
	/* When is upload the binary, the phpbook retrieves the mime binary contents or null. */
	/* When is stage clear, the phpbook retrieves null. */
	/* When is stage keep, the phpbook retrieves the current file mime if exists otherwise returns null. */
	$fileName = $fileStage->filename();

	/* The purpose of this implementation in PHP is a comprehensive guide to handling the files in your requests,
	uploading, removing or keeping the file information as it currently stands. */

//Implementation example

	class Customer {

		private static $Photo_Path = 'my/file/path/to/photo';

		private $id;

		private $name;

		private $photo;

		public function __construct(String $name, String $photo) {

			$this->id; //generate key

			$this->edit($name, $photo);
		}

		public function edit(String $name, String $photo) {

			$this->name = $name;

			$this->photo = new \PHPBook\Storage\FileStage($photo, $this->getId(), Static::$Photo_Path);

		}

		public function getId(): Int {

			return $this->id;

		}

		public function getName(): String {

			return $this->name;

		}

		public function getPhoto(): ?String {

			if (!$this->photo) {

				$this->photo = new \PHPBook\Storage\FileStage(\PHPBook\Storage\FileStage::$Stage_Keep, $this->getId(), Static::$Photo_Path);

			};

			return $this->photo->contents();
		}

		public function save() {

			//store id and name in the database

			//store the stage photo in the storage
			if ($this->photo) {

				$this->photo->persist();

			};

		}

	}
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~50 days

Recently: every ~19 days

Total

17

Last Release

2085d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31623868?v=4)[dz5362](/maintainers/phpbook)[@phpbook](https://github.com/phpbook)

---

Top Contributors

[![phpbook-sources](https://avatars.githubusercontent.com/u/34910819?v=4)](https://github.com/phpbook-sources "phpbook-sources (19 commits)")

---

Tags

phpstoragefastlightweight

### Embed Badge

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

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

###  Alternatives

[rsd/seafile-php-sdk

This is a PHP package for accessing Seafile Web API

3589.1k](/packages/rsd-seafile-php-sdk)

PHPackages © 2026

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