-
-
Notifications
You must be signed in to change notification settings - Fork 1
FileSystem_LocalFile
You may need to assign the namespace to the top of your code
use \Scarlets\Library\FileSystem\LocalFile;The filesystem configuration are stored on /config/filesystem.php.
Then you can pass {the storage name}/your/path to the LocalFile function.
Get contents of a directory as an array.
LocalFile::contents($path);
# Example
$data = LocalFile::contents('{app}/data');Get content of a file.
LocalFile::load($path);
# Example
$data = LocalFile::load('{app}/data/text.inf');Create directory for $path recursively.
LocalFile::mkdir($path);Calculate size of file or directory and return bytes as integer.
LocalFile::size($path);Append data to the end of file.
LocalFile::append($path, $value);Prepend data at the beginning of file.
LocalFile::prepend($path, $value);Put or overwrite file data.
LocalFile::put($path, $value);Search file or folder inside a directory and return as array of string.
LocalFile::search($path, $regex, $recursive = false);Get last modified time of a file.
$timestamp = LocalFile::lastModified($path);Copy file from path to another path.
LocalFile::copy($path, $to);Move file from path to another path.
This can also being used for renaming file/folder.
LocalFile::move($path, $to);Delete file or directory specified by $path.
If you only want to remove contents of the directory
you must set $pathRemove to false.
LocalFile::delete($path, $recursive = false, $pathRemove = true);Read file by line ranges, or you can also read by char ranges.
LocalFile::read($path, $ranges, $readChar = false);
# Example
$array = LocalFile::read('{app}/file.txt', [[0, 2], [5, 7]], true);Tail is used to read lines from bottom of a file.
LocalFile::tail($path, $lines = 1);This feature will need zip extension to be installed and turned on from php.ini.
The $regex parameter is similar with LocalFile::search.
LocalFile::zipDirectory($sourcePath, $outZipPath, $password = '', $regex = '');Extract zip file to an directory.
LocalFile::extractZip($zipPath, $to, $password = '');Check zip status if it has an error.
When check was failed this will return string or error number of ZipArchive.
But if the check was success this will return true, so make sure you used strict equal $msg === true to check if there are no error.
$msg = LocalFile::zipStatus($path);