公方军/file-manager

PHP 文件/目录管理器

1.0.3 2016-09-09 05:16 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:15 UTC


README

PHP 文件/目录管理器

安装

在您的 composer.json 的 "require" 部分添加一行,然后运行命令:composer update

{
	"require":{
		"gongfangjun/file-manager": "*"
	}
}

如何在项目中使用它

include './vendor/autoload.php';

use FileManager\FileManager;

//scan sub docs in the dir
$fm = new FileManager('/data/upload/');
foreach ($fm->scan() as $doc) {
	echo $doc->path,"\n";
}

//scan all the docs in the dir 
function scan($path) {
	$fm = new FileManager($path);
	foreach ($fm->scan() as $doc) {
	    if ($doc->isDir) {
	        echo $doc->path,"\n";
	        scan($doc->path);
	    } else {
	        echo $doc->path,"\n";
	        echo "   |- file size : ", $doc->filesize,"\n";
	        echo "   |- last visit time : ", date('Y-m-d H:i:s', $doc->lastVisitTime),"\n";
	        echo "   `- last modify time : ", date('Y-m-d H:i:s', $doc->lastModTime),"\n";
	    }   
	}   
}

scan('/data/upload/');

//delete a file
$fm = new FileManager('/data/upload/js/inc/bootstrap.js');
$fm->del();

//delete a dir
$fm = new FileManager('/data/upload/js/inc/');
$fm->del();

//read a file
$fm = new FileManager('/data/upload/js/index.js');
$fm->getContent();

//write content to a file
$fm = new FileManager('/data/upload/js/index.js');
$fm->write('var userName = "gongfangjun"');

FileManager\Component\Document 属性

点击此处查看源代码

路径

是否为文件

是否为目录

是否可读

是否可写

最后访问时间

最后修改时间

文件大小

APIs

scan()

  扫描目录

del()

  删除文件或目录

write()

  将内容写入文件

getContent()

  从文件获取内容

createFile()

  创建文件

createDir()

  创建目录