irfantoor/filesystem
Composer 安装命令:
composer require irfantoor/filesystem
包简介
Irfan's Filesystem : A single-file minimum filesystem class, to manage the files and directories.
README 文档
README
A single-file minimum filesystem class, to manage the files and directories.
1. Installation
Install the latest version with
composer require irfantoor/filesystem
Note: Irfan's Filesystem requires PHP 7.1 or newer.
Usage
Initialising
<?php use IrfanTOOR\Filesystem; $fs = new Filesystem('/path/to/mount/as/root/'); // the terminating '/' in path is optional echo $fs->getVersion(); // reports the version of this package
Files
The basic functions related to files are explained through the following examples:
$fs = new IrfanTOOR\Filesystem('My/Base/Path'); # Verifies if the filesystem has the file. $fs->has('file.txt'); // returns true if the filesystem has the file, or false otherwise # Reads and returns the contnets of a file $contents = $fs->read('file.txt'); # Writes to a file # write($file, $contents, $force = false) $fs->write('file1.txt', 'Hello World!'); // writes to file if it does not exists $fs->write('file1.txt', 'Something'); // throws an Exception, as the file already exists $fs->write('file1.txt', 'Hello World!', true); // forces to write to file, even if it exists # Rename a file $fs->rename('hello.txt', 'world.txt'); // returns true if the operation was successful # Copy a file # format: $fs->copy($from, $to, $force = false) $fs->copy('somefile', 'another_file'); // throws an Exception, if the source does not exists $fs->copy('somefile', 'another_file'); // copies to the target provided target doest not exist $fs->copy('somefile', 'another_file'); // throws an Exception, if the target exists $fs->copy('somefile', 'another_file', true); // copies to the target even if the target exists # Remove a file # format: $fs->remove($file) $fs->remove('another_file'); // removes the file, if it exists $fs->remove('another_file'); // throws an Exception if the file does not exist
Directories
The basic operations related to directories are explained through examples as follows:
$fs = new IrfanTOOR\Filesystem('My/Base/Path'); # Verifies if the filesystem has the dir # format: $fs->hasDir($dir) if ($fs->hasDir('abc')) { // verifies if the directory : My/Base/Path/abc exists # ... } # Creates a directory in the FileSystem # format: mkdir(string $dir, bool $recursive = false): bool $fs->mkdir('def'); // creates directory : My/Base/Path/def $fs->mkdir('ghi/jkl'); // returns false if directory My/Base/Path/ghi does not exist $fs->mkdir('ghi/jkl/mno', true); // Creates all of the missing directories in the path # Removes a dir # format: rmdir(string $dir, bool $recursive = false): bool $fs->rmdir('abc'); // removes the relative dir, if its empty $fs->rmdir('ghi'); // fails if it contains files or sub-directory $fs->rmdir('ghi', true); // forces to remove all of the files and sub-folders $fs->rmdir('/', true); // this operation will delete every thing except removing the rootpath # Returns the contents of a directory as an array # format: ls(string $dir, bool $recursive = false): array $list = $fs->ls('abc'); // retuens the list of the entries of abc as an array $list = $fs->ls('ghi'); // retuens the list of the entries of ghi $list = $fs->ls('ghi', true); // retuens the list of the entries of ghi and all the sub-directories
Common
The functions which can be used for both files and directories.
# ... # Returns FileSystem information regarding a file or a directory # format: $fs->info($filename) print_r($fs->info('abc')); /* Array ( [path] => "\/Users\/dev\/hosts\/github\/irfantoor\/filesystem" [pathname] => "\/Users\/dev\/hosts\/github\/irfantoor\/filesystem\/tests" [basename] => "tests" [filename] => "tests" [extension] => "" [created_on] => 1630761810 [accessed_on] => 1630761811 [modified_on] => 1630761810 [group] => 20 [owner] => 502 [inode] => 526945 [perms] => 16877 [size] => 96 [type] => "dir" [readable] => true [writable] => true ) */ print_r($fs->info('tests/FileSystemTest.php')); /* Array ( [path] => "\/Users\/dev\/hosts\/github\/irfantoor\/filesystem\/tests" [pathname] => "\/Users\/dev\/hosts\/github\/irfantoor\/filesystem\/tests\/FileSystemTest.php" [basename] => "FileSystemTest.php" [filename] => "FileSystemTest.php" [extension] => "php" [created_on] => 1630515548 [accessed_on] => 1630761810 [modified_on] => 1630515548 [group] => 20 [owner] => 502 [inode] => 2370274 [perms] => 33188 [size] => 14593 [type] => "file" [readable] => true [writable] => true ) */
About
Requirements Irfan's Filesystem works with PHP 7.3 or above.
License
Irfan's Filesystem is licensed under the GPL v3.0 License - see the LICENSE file for details
irfantoor/filesystem 适用场景与选型建议
irfantoor/filesystem 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「files」 「create」 「local」 「directories」 「copy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 irfantoor/filesystem 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 irfantoor/filesystem 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 irfantoor/filesystem 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An HTML5 upload field for the CMS and frontend forms.
A SDK for working with B2 cloud storage.
Generate Image Collage with Laravel
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
Create restful API client in PHP
A very simple yet useful helper class to handle PHP file uploads.
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2021-01-20