Files and Directories

The default directory structure of hiraeth/app looks like the following:

Directory Description
bin Contains PHP scripts designed to be executed via CLI, e.g. php bin/server
config Contains all Hiraeth configuration information
local Contains end-user PHP source code: classes, interfaces, traits, etc
public Contains web-accessible files/directories (the “document root” for your server)
resources Contains end-user templates and layouts, suggested path also for css/js source
storage Contains application writable files and folders (user uploads, logs, cache)
vendor Contains vendor PHP source code: classes, interface, traits, etc

The parent directory of these is referred to as the “application root.”

Checking for a File or Directory

You can check if a file exists using the hasFile() method. For example, to see if there is a .env file in the application root, you can do:


Similarly, you can check for directories using hasDirectory(). See if a cache directory exists:


File and directory names beginning with a / or <scheme>:// are considered absolute. If the path does not begin with one of these, it will be treated as relative to the application root.

Getting File or Directory Information

To get an SplFileInfo object for a file or directory use the getFile() and getDirectory() methods with the application root relative path:


You can then use the SplFileInfo object to get more information about the file or directory. For example, to get the real absolute path to the public storage directory:


Creating a File or Directory

In many cases you may want to create a file or directory if it does not exist. This is frequently the case, for example, if you’re using getDirectory() to get sub-directories for storing various assets. Adding, TRUE as the second argument to either getFile() or getDirectory() will attempt to create the file or directory if it does not exist.

$app->getFile('storage/sync.lock', TRUE)

When files are created, they will be created using the UMASK set in the .env file. By default, this value is 0002 which means owner and group will be able to write (this allows ACLs to limit permissions on group). You can change this value to modify the umask for all application created files and directories.

UMASK = 0022

In addition to basic file access via Hiraeth\Application, you can install hiraeth\volumes to provide access to external storage interfaces like S3, SFTP, and additional local volumes.

Learn About Volumes