Download the PHP package phpdevcommunity/php-filesystem without Composer

On this page you can find all versions of the php package phpdevcommunity/php-filesystem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-filesystem

PHP Filesystem

A lightweight PHP library for file system operations, including temporary file creation, file manipulation, and metadata handling using SPL.

Installation

You can install this library via Composer. Ensure your project meets the minimum PHP version requirement of 7.4.

Requirements

Table of Contents

  1. TempFile
  2. FileInfo
  3. FileSynchronizer
  4. FileExplorer
  5. FileSplitter

TempFile

The TempFile class provides methods for creating temporary files from base64 data, binary data, and resources.

fromBase64

Create a temporary file from base64 encoded data.

fromBinary

Create a temporary file from binary data.

fromResource

Create a temporary file from a resource.


FileInfo

This guide covers how to use the FileInfo class to manage files in PHP. The FileInfo class allows for working with file metadata, converting files to various formats (base64, binary, data URLs), and performing file operations like comparison and deletion.

1. Instantiating the FileInfo Class

To create a new instance of FileInfo, pass the path of the file to its constructor.

This will throw an exception if the file does not exist or if the provided path is invalid.

2. Getting Basic File Information

Once you have an instance of FileInfo, you can retrieve various details about the file:

3. Reading and Converting File Contents

You can easily convert the file's contents into different formats for storage or transmission:

4. Working with File Metadata

Retrieve detailed metadata about the file:

5. Comparing Files

You can compare two files by content using their SHA-256 hash values:

6. File Deletion

To delete the file associated with the FileInfo object:

Once the delete method is called, the file is permanently removed from the filesystem.

7. Opening Files for Reading or Writing

You can open the file using SplFileObject for reading or writing operations:

8. Error Handling

If the provided file path is invalid or the file does not exist, the constructor will throw a RuntimeException. Always ensure that file paths are validated before instantiating the FileInfo class:


FileSynchronizer

The FileSynchronizer class provides an easy way to synchronize files between two directories, with optional recursive behavior. It copies files from the source directory to the target directory, ensuring that files are only copied if they are missing or have been updated.

1. Instantiating the FileSynchronizer Class

To initialize the FileSynchronizer, you need to provide the source directory, target directory, and an optional logging function to track operations.

Both the source and target must be valid directories, otherwise, the constructor will throw an InvalidArgumentException.

2. Synchronizing Files

Once initialized, you can start synchronizing files from the source to the target directory using the sync() method. If you want to synchronize recursively (i.e., include subdirectories), set the recursive parameter to true.

During synchronization, it copies any files from the source directory that are either missing or outdated in the target directory.

3. Logging Operations

You can pass a custom logging function to track the synchronization actions, such as copying files. The logging function receives an array of information containing the action (copy), the source file path, and the target file path.

If no logging function is provided, the synchronization will proceed without logging any details.

4. Handling Directories

5. Copying Files

The class only copies files when:

Voici une documentation d’utilisation centrée uniquement sur les méthodes publiques de la classe FileExplorer, qui pourrait être utile aux développeurs souhaitant utiliser cette classe dans leurs projets.


FileExplorer

The FileExplorer class is a utility for exploring directories, listing files, and searching files based on patterns or extensions. This guide will walk through how to use its public methods for common file operations.

1. Instantiating the FileExplorer Class

To start exploring a directory, you first need to instantiate the FileExplorer class with a valid directory path.

Note: The constructor will throw an InvalidArgumentException if the provided path is not a valid directory.

2. Listing All Files and Directories: listAll()

The listAll() method returns all files and directories within the specified directory. You can also explore subdirectories by setting the $recursive flag to true.

The result is an array where each item represents a file or directory. Each file or directory is provided as an associative array with these keys:

Example usage:

3. Searching Files by Pattern: searchByPattern()

The searchByPattern() method allows you to search for files that match a specific pattern (e.g., *.txt for text files). You can perform the search recursively by setting the $recursive flag to true.

This method returns an array of files that match the pattern. The result format is the same as in listAll().

Example usage:

4. Searching Files by Extension: searchByExtension()

The searchByExtension() method provides a simpler way to search for files by their extension. You only need to specify the extension, and it will internally use the searchByPattern() method.

This method is ideal when you need to quickly filter files based on their extension without crafting a pattern.

5. Practical Example

Here’s a full example demonstrating how to use the FileExplorer class to list all files in a directory and then search for files with specific extensions.

Voici une documentation d'utilisation centrée sur les méthodes publiques de la classe FileSplitter pour les développeurs souhaitant diviser des fichiers en plusieurs morceaux.


FileSplitter

The FileSplitter class allows developers to split large files into smaller parts, either by specifying the size in megabytes or kilobytes. This guide explains how to use its public methods to perform file splitting operations.

1. Instantiating the FileSplitter Class

To start using the FileSplitter, you need to instantiate it with a FileInfo object representing the file you want to split. You can also specify a directory where the split parts will be saved, but if you don't, the parts will be saved in the same directory as the original file.

If you want to specify a different directory:

Note: The FileInfo class is required to provide file details. Make sure the file path is valid, and the file is readable.

2. Splitting the File by Megabytes: splitMb()

The splitMb() method allows you to split a file into smaller parts based on the size in megabytes. Each part will have the specified size unless the file size is not divisible evenly.

The result is an array of FileInfo objects, each representing a part of the original file.

Example usage:

3. Splitting the File by Kilobytes: splitKb()

If you prefer to specify the size in kilobytes, you can use the splitKb() method. This works similarly to splitMb() but operates in kilobytes.

This also returns an array of FileInfo objects representing each part.

Example usage:

4. General File Splitting: split()

The split() method is the core function that both splitMb() and splitKb() rely on. You can directly use this method to specify any custom size for the chunks in bytes.

Like the other methods, it returns an array of FileInfo objects for the file parts.

5. Practical Example

Here’s a complete example that demonstrates how to split a file into parts and delete the parts afterward.


License

This library is open-source software licensed under the MIT license.


All versions of php-filesystem with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phpdevcommunity/php-filesystem contains the following files

Loading the files please wait ....