1. Go to this page and download the library: Download likeajohny/php-fs 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/ */
use PhpFs\File;
use PhpFs\Exception\FileNotFoundException;
use PhpFs\Exception\PermissionException;
try {
$content = File::read('/path/to/file.txt');
} catch (FileNotFoundException $e) {
// Handle missing file
} catch (PermissionException $e) {
// Handle permission error
}
// Preview files that would be deleted
$paths = File::remove('/path/to/file.txt', dryRun: true);
// Returns: '/path/to/file.txt'
// Preview directory contents that would be deleted
$paths = Directory::remove('/path/to/dir', dryRun: true);
// Returns: ['/path/to/dir/file1.txt', '/path/to/dir/subdir', '/path/to/dir']
// Preview what emptying would delete (excludes directory itself)
$paths = Directory::empty('/path/to/dir', dryRun: true);
// Returns: ['/path/to/dir/file1.txt', '/path/to/dir/subdir']
use PhpFs\File;
// Process large log file line by line
foreach (File::lines('/var/log/large.log') as $lineNum => $line) {
if (str_contains($line, 'ERROR')) {
echo "Error on line $lineNum: $line";
}
}
// Copy large file using streams
File::copyStream('/path/to/large.zip', '/backup/large.zip');
use PhpFs\File;
// Write with exclusive lock (prevents race conditions)
File::writeWithLock('/path/to/config.json', json_encode($config));
// Read with shared lock (allows concurrent reads)
$config = json_decode(File::readWithLock('/path/to/config.json'), true);
use PhpFs\File;
// Atomic write - prevents partial writes if interrupted
File::writeAtomic('/path/to/config.json', json_encode($newConfig));
use PhpFs\Path;
// Prevent directory traversal attacks
$userPath = $_GET['file'];
$basePath = '/var/www/uploads';
if (Path::isInside(Path::join($basePath, $userPath), $basePath)) {
// Safe to access
$content = File::read(Path::join($basePath, $userPath));
}
use PhpFs\Directory;
// Find all PHP files
$phpFiles = Directory::find('/src', fn($path) => str_ends_with($path, '.php'));
// Find files modified in last 24 hours
$recentFiles = Directory::find('/logs', fn($path) =>
is_file($path) && filemtime($path) > time() - 86400
);
// Using glob patterns
$configFiles = Directory::glob('/etc/**/*.conf');
// Old behavior (not recommended)
File::create('/path/to/file.txt', 0766);
Directory::create('/path/to/dir', 0766);
// New defaults (recommended)
File::create('/path/to/file.txt'); // 0644
Directory::create('/path/to/dir'); // 0755
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.