PHP code example of phpfiletool / filetool
1. Go to this page and download the library: Download phpfiletool/filetool 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/ */
phpfiletool / filetool example snippets
HPFileTool\FileTool\FileTool;
// Create a directory
FileTool::createDirectory('storage');
// Create a file
FileTool::createFile('storage', 'example.txt');
// Write content to the file
FileTool::writeFile('storage/example.txt', 'Hello, PHP FileTool!', 1);
// Read file content
$content = FileTool::readFile('storage/example.txt');
echo $content;
use PHPFileTool\FileTool\FileTool;
$file = FileTool::createFile('storage', 'notes.txt');
echo $file;
FileTool::createFile('storage', 'notes', 'txt');
FileTool::createMultipleFiles('storage', 'document', 3, 'txt');
FileTool::writeFile('storage/notes.txt', 'New content', 1);
0 // Append content
1 // Overwrite content
$content = FileTool::readFile('storage/notes.txt');
FileTool::copyFile('storage/notes.txt', 'backup');
FileTool::copyFileContent(
'storage/source.txt',
'storage/destination.txt'
);
FileTool::renamePath('storage/old-name.txt', 'new-name', 'txt');
FileTool::deleteFile('storage/notes.txt');
FileTool::createDirectory('storage/uploads');
FileTool::createDirectory('storage/uploads', 0755);
$files = FileTool::listFiles('storage');
print_r($files);
FileTool::copyAllFiles('storage', 'backup');
FileTool::deleteAllFiles('storage/cache');
FileTool::deleteDirectory('storage/empty-folder');
FileTool::deleteDirectoryRecursive('storage/temp');
use PHPFileTool\FileTool\FileTool;
use PHPFileTool\FileTool\Exceptions\FileNotFoundException;
use PHPFileTool\FileTool\Exceptions\PermissionDeniedException;
use PHPFileTool\FileTool\Exceptions\FileToolException;
try {
$content = FileTool::readFile('storage/missing.txt');
} catch (FileNotFoundException $exception) {
echo 'The file was not found.';
} catch (PermissionDeniedException $exception) {
echo 'Permission denied.';
} catch (FileToolException $exception) {
echo 'FileTool error: ' . $exception->getMessage();
}
PHPFileTool\FileTool\FileTool
FileTool::createDirectory(string $dir, int $permission = 0777): string;
FileTool::deleteDirectory(string $dir): bool;
FileTool::deleteDirectoryRecursive(string $dir): bool;
FileTool::deleteAllFiles(string $dir): bool;
FileTool::listFiles(string $dir): array;
FileTool::createFile(string $dir, string $file, ?string $type = null): string;
FileTool::createMultipleFiles(string $dir, string $file, int $quantity, ?string $type = null): array;
FileTool::copyFile(string $origin, string $destiny): string;
FileTool::copyAllFiles(string $origin, string $destiny): array;
FileTool::copyFileContent(string $fileOrigin, string $fileDestiny): string;
FileTool::readFile(string $dir): string;
FileTool::writeFile(string $dir, string $content, int $overwrite = 0): int;
FileTool::deleteFile(string $path): bool;
FileTool::renamePath(string $oldPath, string $newPath, ?string $type = null): string;
FileTool::renameAllFiles(string $dir, string $fileName, ?string $type = null): array;
FileTool::createDir();
FileTool::createMany();
FileTool::copy();
FileTool::copyAll();
FileTool::copyContent();
FileTool::purge();
FileTool::read();
FileTool::write();
FileTool::removeDir();
FileTool::removeFile();
FileTool::remove();
FileTool::removeAll();
FileTool::rename();
FileTool::renameFile();
FileTool::renameAll();
FileTool::show();
bash
composer analyse