| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Effectra FS is a PHP library that offers a comprehensive set of classes for managing various aspects of the file system, including files, folders, JSON, CSV, and XML. The File class provided by Effectra FS provides static methods for handling file-related operations.
composer require effectra/fsThis command will download and install the Effectra FS library along with its dependencies into your project.
After the installation is complete, you can start using the library by including the necessary files and utilizing the File class as demonstrated in the previous readme file.
The File class provides static methods for managing files and performing file system operations.
Once you have installed the Effectra FS library using Composer, you can start using the File class in your PHP code. Here's an example of how you can utilize some of the methods provided by the File class:
<?php
require_once 'vendor/autoload.php';
use Effectra\Fs\File;
// Example usage of the `exists()` method
$fileExists = File::exists('path/to/file.txt');
if ($fileExists) {
echo "The file exists.";
} else {
echo "The file does not exist.";
}
// Example usage of the `put()` method
$fileContent = 'Hello, world!';
$writeSuccess = File::put('path/to/newfile.txt', $fileContent);
if ($writeSuccess !== false) {
echo "The file was successfully written.";
} else {
echo "Failed to write the file.";
}
// Example usage of the `getContent()` method
$fileContent = File::getContent('path/to/file.txt');
echo "The file content is: " . $fileContent;
// Example usage of the `delete()` method
$deleteSuccess = File::delete('path/to/file.txt');
if ($deleteSuccess) {
echo "The file was successfully deleted.";
} else {
echo "Failed to delete the file.";
}
// ... Continue using other methods provided by the `File` class
?>In this example, we demonstrate the usage of methods such as exists(), put(), getContent(), and delete() from the File class. You can explore the various methods available in the class and use them according to your file system requirements.
Make sure to adjust the file paths according to your specific use case.
Remember to include the Composer-generated autoloader (require_once 'vendor/autoload.php';) at the beginning of your PHP script to ensure that the Effectra FS library is properly loaded.
Utility class for working with directories.
use Effectra\Fs\Directory;
// Check if a path is a directory
$isDirectory = Directory::isDirectory('/path/to/directory');
// Create a new directory
$created = Directory::make('/path/to/new_directory');
// Delete a directory
$deleted = Directory::delete('/path/to/directory');
// Delete all directories within a directory
$deletedAll = Directory::deleteDirectories('/path/to/parent_directory');
// Get a directory instance
$dirInstance = Directory::instance('/path/to/directory');
// Copy a directory recursively to a destination
$copied = Directory::copy('/path/to/source_directory', '/path/to/destination_directory');
// Retrieve the name of a directory
$directoryName = Directory::name('/path/to/directory');
// Rename a directory
$renamed = Directory::rename('/path/to/old_directory', '/path/to/new_directory');
// Retrieve the full path of a directory's parent
$parentDirectory = Directory::fullName('/path/to/directory');
// Retrieve the files and directories within a directory
$entries = Directory::read('/path/to/directory');
// Retrieve the parent directory of a given directory path
$parentDirectory = Directory::parent('/path/to/directory');
// Check if a directory is considered private
$isPrivate = Directory::isPrivate('/path/to/directory');
// Retrieve the files within a directory
$files = Directory::files('/path/to/directory', true, ['txt', 'csv']);
// Check if a directory has any files
$hasFiles = Directory::hasFiles('/path/to/directory');
// Delete files within a directory
$deletedFiles = Directory::deleteFiles('/path/to/directory', ['txt', 'csv']);
// Retrieve the directories within a directory
$directories = Directory::directories('/path/to/directory', true);
// Empty a directory by deleting its files and subdirectories
Directory::empty('/path/to/directory');Note: Please make sure to replace /path/to with the actual path in your code.
Effectra\Fs\Path is a utility class for manipulating file paths in PHP.
The Path class provides several useful methods for manipulating file paths:
Retrieves the directory separator for the current platform.
Example:
$separator = \Effectra\Fs\Path::ds();
echo $separator; // Outputs '\' on Windows, '/' on Unix-like systemsFormats a given path by replacing forward slashes, backslashes, and multiple separators with the directory separator.
Example:
$path = \Effectra\Fs\Path::format('path/to//file');
echo $path; // Outputs 'path/to/file' on all platformsRemoves the extension from a given path.
Example:
$path = \Effectra\Fs\Path::removeExtension('file.txt');
echo $path; // Outputs 'file'Sets the extension of a given path.
Example:
$path = \Effectra\Fs\Path::setExtension('file', 'txt');
echo $path; // Outputs 'file.txt'Effectra\Fs\FileData is a utility class for converting files to data URLs and vice versa in PHP.
##Usage
The FileData class provides two methods for converting files to data URLs and vice versa:
Converts a file to a data URL.
Parameters:
Returns:
Example:
$fileData = new \Effectra\Fs\FileData();
$dataUrl = $fileData->fileToDataUrl('/path/to/file.jpg');
if ($dataUrl !== false) {
echo $dataUrl;
} else {
echo "Failed to convert the file to a data URL.";
}Converts a data URL to a file.
Parameters:
Returns:
Example:
$fileData = new \Effectra\Fs\FileData();
$result = $fileData->dataUrlToFile('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAAAAAAAD...', '/path/to/output.jpg');
if ($result) {
echo "File saved successfully.";
} else {
echo "Failed to save the file.";
}The FileEncryption class provides utility methods for encrypting and decrypting files.
use Effectra\Fs\FileEncryption;
// Create an instance of FileEncryption with the encryption key
$fileEncryption = new FileEncryption('your-encryption-key');
// Encrypt a file
$fileEncryption->encryptFile('path/to/source/file.txt', 'path/to/destination/encrypted-file.txt');
// Decrypt a file
$fileEncryption->decryptFile('path/to/source/encrypted-file.txt', 'path/to/destination/decrypted-file.txt');Make sure to replace 'your-encryption-key' with your own encryption key.
use Effectra\Fs\FileEncryption;
$fileEncryption = new FileEncryption('my-secret-key');
// Encrypt a file
$fileEncryption->encryptFile('data.txt', 'encrypted-data.txt');
// Decrypt a file
$fileEncryption->decryptFile('encrypted-data.txt', 'decrypted-data.txt');In the above example, the FileEncryption class is used to encrypt the content of the data.txt file and store the encrypted data in the encrypted-data.txt file. It also provides a method to decrypt the encrypted data and save it in a separate file.
The FileEncryption class uses the AES-256-CBC encryption algorithm with a randomly generated initialization vector (IV) for each encryption operation.
Note: Make sure to keep the encryption key secure and do not share it with unauthorized individuals.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
This package is open-source software licensed under the MIT license.
| Back | FazBrowse Home | New Git URL |