Download the PHP package sigmaphp/sigmaphp-filesystem without Composer
On this page you can find all versions of the php package sigmaphp/sigmaphp-filesystem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sigmaphp/sigmaphp-filesystem
More information about sigmaphp/sigmaphp-filesystem
Files in sigmaphp/sigmaphp-filesystem
Package sigmaphp-filesystem
Short Description Filesystem utilities
License MIT
Informations about the package sigmaphp-filesystem
SigmaPHP-Filesystem
The SigmaPHP-Filesystem package provides a simple and consistent interface for working with files and directories. It abstracts common filesystem operations such as creating, reading, writing, copying, moving, renaming, and removing files and directories.
The package is designed to keep filesystem operations straightforward while providing a reusable interface that can be integrated into SigmaPHP applications and other PHP projects.
Installation
Documentation
Basic Usage
The Filesystem class provides the implementation of FilesystemInterface and can be instantiated directly when filesystem operations are required.
Once the filesystem instance has been created, it can be used to perform common file and directory operations.
For example, a file can be created and written to using the following:
The same instance can then be used to read the file:
Available Methods
list()
Lists all files inside a directory and its sub-directories.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The directory path to search. |
$includeFullPath |
bool |
Whether to include the full path for each file. |
$withExtension |
bool |
Whether to include file extensions. |
Returns an array of file paths or file names.
exists()
Checks whether a file or directory exists.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The file or directory path. |
Returns true when the path exists, otherwise false.
dirHas()
Checks whether a directory contains a specific file or subdirectory.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The directory to search. |
$target |
string |
The file or subdirectory to look for. |
Returns true when the target exists inside the directory.
create()
Creates a new file with the specified permissions.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The path of the file to create. |
$permission |
int |
The permissions to assign to the file. |
Returns true when the file is created successfully.
rename()
Renames a file or directory.
| Parameter | Type | Description |
|---|---|---|
$old |
string |
The current path. |
$new |
string |
The new path. |
Returns true when the operation succeeds.
copy()
Copies a file to another location.
| Parameter | Type | Description |
|---|---|---|
$src |
string |
The source file path. |
$dest |
string |
The destination path. |
Returns true when the file is copied successfully.
move()
Moves a file to another location.
| Parameter | Type | Description |
|---|---|---|
$src |
string |
The source file path. |
$dest |
string |
The destination path. |
Returns true when the file is moved successfully.
remove()
Removes a file.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The file path to remove. |
Returns true when the file is removed successfully.
write()
Writes content to a file. Existing content may be replaced.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The file path. |
$content |
mixed |
The content to write. |
Returns true when the content is written successfully.
append()
Appends content to the end of an existing file.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The file path. |
$content |
mixed |
The content to append. |
Returns true when the content is appended successfully.
read()
Reads content from a file.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The file path. |
$offset |
int |
The position from which to start reading. |
$length |
int |
The maximum amount of content to read. |
Returns the file content as a string.
createDir()
Creates a directory.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The directory path to create. |
$permission |
int |
The permissions to assign to the directory. |
$recursive |
bool |
Whether parent directories should also be created. |
Returns true when the directory is created successfully.
removeDir()
Removes a directory and its contents.
| Parameter | Type | Description |
|---|---|---|
$path |
string |
The directory path to remove. |
Returns true when the directory and its contents are removed successfully.
License
(SigmaPHP-Filesystem) released under the terms of the MIT license.