acide/acfilemanager

这是一个神奇的PHP文件管理库

dev-master 2020-08-07 13:59 UTC

This package is auto-updated.

Last update: 2024-09-07 23:15:14 UTC


README

AC FileManager

version license size

PHP文件和目录管理库

需求

此库支持PHP 5.6或更高版本

安装

安装此库的首选方式是通过 Composer

composer require acide/acfilemanager

快速入门

使用Composer使用此库

require __DIR__ . '/vendor/autoload.php';

use ACFileManager\Src\File;

可用方法

File::exists($path)
File::scanPath($path , $order);

如果可选的 $order 设置为 SCANDIR_SORT_DESCENDING,则排序顺序为降序字母顺序。如果设置为 SCANDIR_SORT_NONE,则结果未排序。

File::filterScan($path , $filters , $order)

# 一个简单的filterScan()示例

$result = File::filterScan(
    '/path/tmp' ,
    array('readme.txt' , 'sources')
);

print_r($result);

列出 /path/tmp 中的所有文件和目录,并从结果中删除 readme.txt 文件和 sources 目录

File::getFiles($path , $regex , $depth , $order)
File::getDirectories($path , $regex , $depth , $order)
File::deleteFile($path)
File::deleteDirectory($path)
File::emptyDirectory($path , $except , $self_delete)

# 一个简单的emptyDirectory()示例

File::emptyDirectory('/to/path/sample' , [
    '/to/path/sample/Application' ,
    '/to/path/sample/webpack.config.js'
]);
File::makeDirectory($path , $mode)

默认模式是 0777,这意味着最广泛可能的访问权限。有关模式的更多信息,请参阅chmod() 页面的详细信息。

File::addFileContent($path , $content , $mode)

如果您在不存在文件上使用addFileContent(),则会创建它,前提是文件以写入 (w) 或追加 (a) 方式打开

# 一个简单的addFileContent()示例

$result = File::addFileContent(
    '/path/tmp/doc.txt' ,
    'This is for test :)'
);

var_dump($result);
File::copyDirectoryRecursively($from , $to)
File::copyFile($from , $to)
File::rename($path , $new_name)

# 一个简单的rename()示例

$result = rename(
    '/path/tmp/File1.txt' ,
    'File2.txt'
);

var_dump($result);
File::moveFile($from_dir , $to_dir , $name)

# 一个简单的moveFile()示例

$result = File::moveFile(
    '/path/tmp' ,
    '/path/another' ,
    'Files.txt'
);

var_dump($result);

/path/tmp 目录中的 Files.txt 移动到 /path/another 目录

File::moveDirectory($from_dir , $to_dir , $dir)
File::isFileEmpty($path)
File::isDirectoryEmpty($path)
File::cleanPath($path)

# 一个简单的cleanPath()示例

$result = File::cleanPath('path/tmp/');

echo $result;

结果是 path/tmp

File::fixPath($path)

# Linux操作系统中的简单fixPath()示例

$result = File::fixPath('var/www/html/acide\images\test.png');

echo $result;

结果是 var/www/html/acide/images/test.png

File::getDirectoryTree($path)
--- /root
    |
    |----- /src
    |      |----- main.js
    |      |----- home.js
    |
    |----- example.text
    |----- simple.php 

文件管理器返回上述文件结构如下

array (size=2)
  '../root' => 
    array (size=3)
      'src' => string 'directory' (length=3)
      'example.text' => string 'file' (length=12)
      'simple.php' => string 'file' (length=10)
  '../root/src' => 
    array (size=2)
      'main.js' => string 'file' (length=7)
      'home.js' => string 'file' (length=7)
File::getBaseName($path)
File::getFileContent($path)

许可证

本项目采用Creative Commons Zero v1.0通用许可证。有关更多信息,请参阅LICENSE 文件。