max-s-lab / filesystem
A package for convenient work with local filesystem.
v1.3.0
2024-02-26 05:39 UTC
Requires
- php: >=7.3
- ext-fileinfo: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- phpro/grumphp: ^1.5
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ~9.6.0
README
This is a library for convenient and uncomplicated work with local filesystem without unnecessary dependencies, which uses only PHP.
Advantages
- Easy to use.
- Does not require dependencies.
- Allows you to upload files without creating a directory for them in advance.
- 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');