file-manager
A file/dir manager for php, (*1)
install
add a line to the "require" section in your composer.json,then run the command: composer update, (*2)
{
"require":{
"gongfangjun/file-manager": "*"
}
}
how to use it in your project
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"');
property of FileManager\Component\Document
click here to see the source code, (*3)
path, (*4)
isFile, (*5)
isDir, (*6)
isReadable, (*7)
isWritable, (*8)
lastVisitTime, (*9)
lastModTime, (*10)
filesize, (*11)
apis
scan(), (*12)
scan a dir, (*13)
del(), (*14)
del a file or a dir, (*15)
write(), (*16)
write content to a file, (*17)
getContent(), (*18)
get content from a file, (*19)
createFile(), (*20)
create a file, (*21)
createDir(), (*22)
create a dir, (*23)