简单易用的文件管理器

2.4 2024-06-24 19:17 UTC

This package is auto-updated.

Last update: 2024-09-24 19:57:43 UTC


README

EzFile是一个免费、非盈利的PHP库,旨在简化Web开发中的文件和目录操作。它侧重于易用性,提供高效的工具以完成常见任务,如创建、重命名、移动、复制、删除、上传、下载和操作文件和文件夹。EzFile可以加速Web开发,使文件和目录操作更加容易,从而提高生产力。

要求

安装

使用Composer安装EzFile

composer require amplie-solucoes/ezfile

注意

如果您需要处理大型文件,请确保在您的php.ini文件中更改以下参数:

  • memory_limit
  • upload_max_filesize
  • post_max_size

如何使用

EzFile的目标是成为一个简单且易于访问的库,因此,所有代码都设计为静态执行,以便于代码的工作和操作。

此外,需要注意的是,下面列出的每个函数都包含一个名为"force"的参数。此参数的目的是允许操作位于指定主路径之外的位置。请参考提供的示例以了解清楚。

存在函数
//Validate if a Directory or File exists
EzFile::exists('your_path');

//Using 'force' paramn to validate outsite main path
EzFile::exists('your_path', true);

/*
====== [ Function Return ] ===== 
EXISTS: true
NOT EXISTS: false
*/
创建函数
//Create a Directory or File
EzFile::create('your_path');

//Create a Directory or File replacing special chars and set all to lowercase
EzFile::create('your_path', true);

//Using 'force' paramn to create outsite main path
EzFile::create('your_path', false, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
写入函数
//Write a file replacing the content (the function will create the file if not exist)
EzFile::write('your_file_path', 'any_content_you_want');

//using 'replaceContent' as FALSE, to append the content at the end of file.
EzFile::write('your_file_path', 'any_content_you_want', false);

//Using 'force' paramn to write in a file outsite main path
EzFile::write('your_file_path', 'any_content_you_want', false, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
读取函数
//Read the file that you want
EzFile::read('your_file_path');

//Using 'force' paramn to read a file outsite main path
EzFile::read('your_file_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: *The File Content*
ERROR: ['error' => true, 'message' => 'error_message']
*/
重命名函数
//Rename a Directory or File
EzFile::rename('current_path', 'renamed_path');

//Rename a Directory or File replacing special chars and set all to lowercase
EzFile::rename('current_path', 'renamed_path', true);

//Using 'force' paramn to rename outsite main path
EzFile::rename('current_path', 'renamed_path', false, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
移动函数
//Move a Directory or File
EzFile::move('current_path', 'move_path');

//Using 'force' paramn to move outsite main path
EzFile::move('current_path', 'move_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
复制函数
//Copy a Directory (and all contents inside) or File
EzFile::copy('current_path', 'copy_path');

//Using 'force' paramn to copy outsite main path
EzFile::copy('current_path', 'copy_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
更改路径权限函数
//Permission code set in a Directory or File
EzFile::changePermissions('your_path', 0777);
EzFile::changePermissions('your_path', 0666);
EzFile::changePermissions('your_path', 0700);
//... and other codes that you need

//Using 'force' paramn to change permissions outsite main path
EzFile::changePermissions('your_path', 0777, true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
路径信息函数
//Info of the Directory or File
EzFile::pathInfo('your_path');

//Using 'force' paramn to get pathinfo outsite main path
EzFile::pathInfo('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: [array_with_all_informations_that_you_need]
ERROR: ['error' => true, 'message' => 'error_message']
*/
列表函数
//List a Directory
EzFile::list('your_path');

//Using 'force' paramn to list outsite main path
EzFile::list('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: [array_with_all_informations_that_you_need]
ERROR: ['error' => true, 'message' => 'error_message']
*/
压缩文件夹函数
//Zip a Directory with all contents inside
EzFile::zip('your_folder_path', 'zip_path');

//Using 'force' paramn to zip outsite main path
EzFile::zip('your_folder_path', 'zip_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
解压文件夹函数
//Unzip a file with all contents inside (ONLY ZIP FILES)
EzFile::unzip('your_zip_file_path', 'unzip_path');

//Using 'force' paramn to unzip outsite main path (ONLY ZIP FILES)
EzFile::unzip('your_zip_file_path', 'unzip_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
删除函数
//Delete a Directory (and all contents inside) or File
EzFile::delete('your_path');

//Using 'force' paramn to delete outsite main path
EzFile::delete('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: true
ERROR: ['error' => true, 'message' => 'error_message']
*/
上传函数
//Upload a Directory (and all contents inside) or File(s)
EzFile::upload('upload_path', $_FILES);

//Uploading and renaming (the lib will interate automatically as new_name_1... new_name_2....)
EzFile::upload('upload_path', $_FILES, 'new_name');

//Uploading accept only files with
EzFile::upload('upload_path', $_FILES, false, ['txt', 'png', 'json', /* ... */]);

//Using 'force' paramn to Upload outsite main path
EzFile::upload('upload_path', $_FILES, false, [], true);

/*
====== [ Function Return ] ===== 
SUCCESS: ['success' => [], 'fail' => [], 'denied' => []]
ERROR: ['error' => true, 'message' => 'error_message']
*/
下载函数
//Download a Directory (and all contents inside) or File
EzFile::download('your_path');

//Using 'force' paramn to download outsite main path
EzFile::download('your_path', true);

/*
====== [ Function Return ] ===== 
SUCCESS: The user will receive the download item
ERROR: ['error' => true, 'message' => 'error_message']
*/
计算单元常量
// Get size unit constants
EzFile::UNIT_BYTES;      //Return (string): "B"
EzFile::UNIT_KILOBYTES;  //Return (string): "KB"
EzFile::UNIT_MEGABYTES;  //Return (string): "MB"
EzFile::UNIT_GIGABYTES;  //Return (string): "GB"
EzFile::UNIT_TERABYTES;  //Return (string): "TB"
EzFile::UNIT_PETABYTES;  //Return (string): "PB"
EzFile::UNIT_EXABYTES;   //Return (string): "EB"
EzFile::UNIT_ZETTABYTES; //Return (string): "ZB"
EzFile::UNIT_YOTTABYTES; //Return (string): "YB"
单位格式化函数
// Format the value for human reading

//Formatting bytes Value
EzFile::sizeUnitFormatter(100); //Return (string): 100 B

//Formatting by setting computational unit
EzFile::sizeUnitFormatter(5, EzFile::UNIT_GIGABYTES);   //Return (string): 5 GB
EzFile::sizeUnitFormatter(500, EzFile::UNIT_GIGABYTES); //Return (string): 500 GB
EzFile::sizeUnitFormatter(1, EzFile::UNIT_TERABYTES);   //Return (string): 1 TB

//Formatting by setting computational unit with data in byte number
EzFile::sizeUnitFormatter(1, EzFile::UNIT_TERABYTES, true); //Return (string): 1099511627776 B

/*
====== [ Function Return ] ===== 
SUCCESS: Return a string value
ERROR: ['error' => true, 'message' => 'error_message']
*/

代码示例

以下是一个简单的示例,说明如何使用某些函数

//Import the lib
use AmplieSolucoes\EzFile\EzFile;

//Example Creating a file/Directory
$ezFile = EzFile::create('your_path');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked
}

//Example renaming a file/Directory
$ezFile = EzFile::rename('current_path', 'renamed_path');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked
}

//Example getting the pathinfo from file/Directory
$ezFile = EzFile::pathInfo('your_path');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked, get all data from the array $ezFile
}

//Example uploading file(s)/Directory(ies)
$ezFile = EzFile::upload('upload_path', $your_files_in_array);
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked, get all data from the array $ezFile
}

//Example writing file(s)
$ezFile = EzFile::write('file_path_name_with_extension', 'any_content');
if(isset($ezFile['error'])){
    // Ops, errors found... put your code logic here with message $ezFile['message']
} else {
    // It Worked
}

* 重要 *

如果"path"参数发送有错误,上述所有函数都将返回一个数组

['error' => true, 'message' => 'error_message']

测试

  • 所有测试都可以在EzFile/tests/EzFileTest.php中找到
  • 在控制台输入运行测试
./vendor/bin/phpunit tests/ --colors=always

捐赠

如果您发现这个项目有帮助和有价值,请考虑支持我。您的贡献有助于我维护和改进这个库,使其免费供大家使用。每一分钱都很有帮助!

在此捐赠

感谢您的慷慨和支持!🙏

此README提供了EzFile库的概述、其功能和用法。可以根据需要调整以适应您的特定项目。