max-s-lab/filesystem

A package for convenient work with local filesystem.

v1.3.0 2024-02-26 05:39 UTC

This package is auto-updated.

Last update: 2024-04-06 15:04:24 UTC


README

Latest Version php 7.3+ Software License

This is a library for convenient and uncomplicated work with local filesystem without unnecessary dependencies, which uses only PHP.

Advantages

  1. Easy to use.
  2. Does not require dependencies.
  3. Allows you to upload files without creating a directory for them in advance.
  4. Allows you not to worry about symbols separating directories and adapts to the operating system.

Installation

Run

$ php composer.phar require max-s-lab/filesystem

or add

"max-s-lab/filesystem": "^1.3"

to the require section of your composer.json file.

Usage

This library can work in two modes: normal and strict. By default, the normal mode is used.

If an error has occurred and strict mode is enabled, exceptions will be thrown.

If strict mode is disabled, then exceptional situations will be handled without throwing exceptions.

Initializing

use MaxSLab\Filesystem\Filesystem;

$filesystem = new Filesystem('/var/www/some-directory');

Common methods

$filesystem->prepareFullPath('test.txt');
$filesystem->prepareFullPath('test-directory');
$filesystem->listPathnames('*.txt');

Check existing methods

$filesystem->fileExists('test.txt');
$filesystem->directoryExists('test-directory');

Uploading and deleting a file

$filesystem->uploadFile('test.txt', 'Test');
$filesystem->deleteFile('test.txt');

Copying and moving a file

$filesystem->copyFile('test.txt', 'copy-directory/copy.txt');
$filesystem->moveFile('test.txt', 'move-directory/copy.txt');

File get methods

$filesystem->getFileContent('test.txt');
$filesystem->getFileSize('test.txt');
$filesystem->getFileMimeType('test.txt');
$filesystem->getFileLastModifiedTime('test.txt');

Creating and deleting a directory

$filesystem->createDirectory('test-directory');
$filesystem->deleteDirectory('test-directory');

Methods for cleaning the directory

$filesystem->deleteAllDirectories('test-directory');
$filesystem->deleteEmptyDirectories('test-directory');