tereta / storage
Tereta/Storage is a package for working with file resources.You work with them the same way regardless of where the storage is located. The `local` and `sftp` drivers are supported out of the box.
Requires
- php: >=8.2
Requires (Dev)
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- squizlabs/php_codesniffer: ^3.13
Suggests
- ext-curl: *
- ext-ssh2: Required for the Tereta\Storage\Strategies\Sftp strategy
This package is not auto-updated.
Last update: 2026-07-12 17:29:23 UTC
README
๐ English | ะ ัััะบะธะน | ะฃะบัะฐัะฝััะบะฐ
Introduction
Tereta/Storage is a package for working with file resources.
You work with them the same way regardless of where the storage is located. The local and sftp drivers are supported out of the box.
Requirements
- PHP version 8.2 or newer.
- The
ext-ssh2extension โ required only for thesftpdriver. It is not needed for local storage (local).
Installation
composer require tereta/storage
Git Repository
https://gitlab.com/tereta/library/storage
Usage
All work is done through the Tereta\Storage\Filesystem facade.
Available methods:
setStrategy(string $name, ...$attributes)โ choose where to store files (localorsftp).exists(string $path)โ check whether a file exists. Returnstrueorfalse.read(string $path)โ read the file contents. Returns a string.write(string $path, string $contents, int $mode = 0644)โ save (or create) a file.copy(string $source, string $destination, int $mode = 0644)โ copy a file.move(string $source, string $destination, int $mode = 0644)โ move or rename a file.remove(string $path, bool $recursively = false)โ delete a file. To recursively delete a folder with all its contents, passtrueas the second argument.list(string $path)โ get the list of files in a folder. Returns an array of names.
Local filesystem
Use the local strategy for the local filesystem
use Tereta\Storage\Filesystem;
$storage = (new Filesystem())->setStrategy('local', '/var/www/files');
For files on an SFTP server โ the sftp strategy
$storage = (new Filesystem())->setStrategy('sftp', 'example.com', 'user', 'secret', '/home/user/files');
Examples
Below are the available methods and examples for working with the filesystem:
// Write a file
$storage->write('notes/hello.txt', 'Hello!');
// Read
$text = $storage->read('notes/hello.txt');
// Check whether a file exists
if ($storage->exists('notes/hello.txt')) {
// ...
}
// Copy and move
$storage->copy('notes/hello.txt', 'notes/backup.txt');
$storage->move('notes/hello.txt', 'archive/hello.txt');
// View the list of files in a folder
$files = $storage->list('notes');
// Delete a file (or an entire folder โ pass true as the second argument)
$storage->remove('archive/hello.txt');