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.

Maintainers

Package info

gitlab.com/tereta/library/storage

Homepage

Issues

pkg:composer/tereta/storage

Transparency log

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

0.0.7 2026-07-12 20:28 UTC

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-ssh2 extension โ€” required only for the sftp driver. 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 (local or sftp).
  • exists(string $path) โ€” check whether a file exists. Returns true or false.
  • 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, pass true as 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');