# Filesystem

Phenix provides the Phenix\Facades\File facade, which is based on the File (opens new window) package, it provides an abstraction layer and non-blocking file access solution that keeps your application responsive.

# Read

You can read a file using the get method, which takes the file path as an argument.

use Phenix\Facades\File;


# Write

To write to files you can use the put method, the first argument is the file path and the second argument is the content to write.

use Phenix\Facades\File;

File::put('path/to/file.txt', 'Amphp is amazing');

# Exists

The exists method allows you to check if a file or directory exists and returns a boolean value.

use Phenix\Facades\File;


# Checking the type

# Directories

Additionally you can check if a path corresponds to a directory.

use Phenix\Facades\File;


# Files

Likewise you can check if a path corresponds to a file:

use Phenix\Facades\File;


# Make directories

The createDirectory method allows the creation of directories in the indicated path, additionally you can indicate the permissions to be assigned in the second argument, by default the mode is 0755.

use Phenix\Facades\File;


# Open files

Finally, the openFile method returns an instance of the Amp\File\File class, the second argument corresponds to the file opening mode, by default in w, the same modes used by the native PHP function fopen (opens new window), this function should not be used in the Phenix framework.

use Phenix\Facades\File;


Methods provided by the Amp\File\File class: read, seek, tell, eof, isSeekable, getPath, getMode, truncate.