gongfangjun/file-manager

A file/dir manager for php

1.0.3 2016-09-09 05:16 UTC

This package is not auto-updated.

Last update: 2025-01-18 21:36:10 UTC


README

A file/dir manager for php

install

add a line to the "require" section in your composer.json,then run the command: composer update

{
	"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

path

isFile

isDir

isReadable

isWritable

lastVisitTime

lastModTime

filesize

apis

scan()

   scan a dir

del()

   del a file or a dir

write()

   write content to a file

getContent()

   get content from a file

createFile()

   create a file

createDir()

   create a dir