1. Go to this page and download the library: Download irfantoor/filesystem library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
irfantoor / filesystem example snippets
use IrfanTOOR\Filesystem;
$fs = new Filesystem('/path/to/mount/as/root/'); // the terminating '/' in path is optional
echo $fs->getVersion(); // reports the version of this package
$fs = new IrfanTOOR\Filesystem('My/Base/Path');
# Verifies if the filesystem has the file.
$fs->has('file.txt'); // returns true if the filesystem has the file, or false otherwise
# Reads and returns the contnets of a file
$contents = $fs->read('file.txt');
# Writes to a file
# write($file, $contents, $force = false)
$fs->write('file1.txt', 'Hello World!'); // writes to file if it does not exists
$fs->write('file1.txt', 'Something'); // throws an Exception, as the file already exists
$fs->write('file1.txt', 'Hello World!', true); // forces to write to file, even if it exists
# Rename a file
$fs->rename('hello.txt', 'world.txt'); // returns true if the operation was successful
# Copy a file
# format: $fs->copy($from, $to, $force = false)
$fs->copy('somefile', 'another_file'); // throws an Exception, if the source does not exists
$fs->copy('somefile', 'another_file'); // copies to the target provided target doest not exist
$fs->copy('somefile', 'another_file'); // throws an Exception, if the target exists
$fs->copy('somefile', 'another_file', true); // copies to the target even if the target exists
# Remove a file
# format: $fs->remove($file)
$fs->remove('another_file'); // removes the file, if it exists
$fs->remove('another_file'); // throws an Exception if the file does not exist
$fs = new IrfanTOOR\Filesystem('My/Base/Path');
# Verifies if the filesystem has the dir
# format: $fs->hasDir($dir)
if ($fs->hasDir('abc')) { // verifies if the directory : My/Base/Path/abc exists
# ...
}
# Creates a directory in the FileSystem
# format: mkdir(string $dir, bool $recursive = false): bool
$fs->mkdir('def'); // creates directory : My/Base/Path/def
$fs->mkdir('ghi/jkl'); // returns false if directory My/Base/Path/ghi does not exist
$fs->mkdir('ghi/jkl/mno', true); // Creates all of the missing directories in the path
# Removes a dir
# format: rmdir(string $dir, bool $recursive = false): bool
$fs->rmdir('abc'); // removes the relative dir, if its empty
$fs->rmdir('ghi'); // fails if it contains files or sub-directory
$fs->rmdir('ghi', true); // forces to remove all of the files and sub-folders
$fs->rmdir('/', true); // this operation will delete every thing except removing the rootpath
# Returns the contents of a directory as an array
# format: ls(string $dir, bool $recursive = false): array
$list = $fs->ls('abc'); // retuens the list of the entries of abc as an array
$list = $fs->ls('ghi'); // retuens the list of the entries of ghi
$list = $fs->ls('ghi', true); // retuens the list of the entries of ghi and all the sub-directories