darkotodoric / efficient-file-management
基于PHP的文件管理系统,旨在实现大量文件的无缝存储和检索,同时保持最佳性能
v1.0
2024-01-13 19:03 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.6
README
EfficientFileManagement
类是一个高效的PHP解决方案,用于管理和存储大量文件,可能高达数十亿,同时保持卓越的性能。它通过根据唯一的ID(来自数据库或其他来源)和文件扩展名对文件进行分层文件夹结构组织来实现这种可扩展性。
安装
使用以下命令安装最新版本:
$ composer require darkotodoric/efficient-file-management
用法
require_once 'vendor/autoload.php'; // Define the folder path where files will be saved $baseFolderPath = '/mnt/efficient-file-management/'; // Define allowed extensions $allowedExtensions = ['json', 'xml', 'txt']; // Define the division number (Maximum number of files in one folder) $divisionNumber = 50000; $efficientFileManagement = new EfficientFileManagement($baseFolderPath, $allowedExtensions, $divisionNumber); // Get IDs from MySQL or other data source $ids = [1337, 5162, 70312, 155312, 160312, 525312]; // Save content foreach ($ids as $id) { $data = json_encode(['name' => 'File with ID ' . $id]); $efficientFileManagement->saveContent($id, 'json', $data); } // Get content foreach($ids as $id){ $data = $efficientFileManagement->getContent($id, 'json'); } // Delete content foreach($ids as $id){ $data = json_encode(['name' => 'File with ID ' . $id]); $efficientFileManagement->deleteContent($id, 'json'); }
文件夹和文件结构
以下是一个使用 EfficientFileManagement
类存储具有ID和扩展名的文件的文件夹结构和文件的示例:假设我们有以下文件
- 具有ID
123456
、987654
、555555
和扩展名json
的文件 - 具有ID
987654
和扩展名xml
的文件 - 具有ID
555555
和扩展名txt
的文件
结果文件夹结构可能如下所示
/mnt/efficient-file-management/
├── json/
│ ├── 2/
│ │ └── 123456.json
│ ├── 19/
│ │ └── 987654.json
│ ├── 11/
│ │ └── 555555.json
├── xml/
│ ├── 19/
│ │ └── 987654.xml
├── txt/
│ ├── 11/
│ │ └── 555555.txt
在这个结构中
- 具有
.json
扩展名的文件存储在json
文件夹中。 - 具有
.xml
扩展名的文件存储在xml
文件夹中。 - 具有
.txt
扩展名的文件存储在txt
文件夹中。 - 每个文件夹进一步根据文件ID除以50000的整数除法组织成子文件夹。这种分层组织确保即使有大量文件,系统仍然高效且易于管理。
贡献
欢迎贡献!请随意提出问题或提交拉取请求以改进此项目。