FileSystem
class FileSystem (View source)
The FileSystem class.
Methods
Delete a file.
Return the extension for a given file.
Get file extension for images based on mime types.
Return the path of the temp dir if it is writable by the webserver.
A wrapper for PHP's built-in glob function.
Find files by using the glob() method and filter the resulting array by a regex pattern.
Tests if a string is a file name with an allowed file extension.
Create directory if not existing.
Replace all backslashes in a given path with forward slashes.
Write content to a file and create the parent directory if needed.
Details
at line 55
static bool
deleteFile(string $file)
Delete a file.
at line 69
static string
getExtension(string $file)
Return the extension for a given file.
at line 85
static mixed
getImageExtensionFromMimeType(string $file)
Get file extension for images based on mime types.
at line 124
static string
getTmpDir()
Return the path of the temp dir if it is writable by the webserver.
In any case, '/tmp' is the preferred directory, because of automatic cleanup at reboot, while other locations like '/var/tmp' do not get purged by the system. But since '/tmp' is only available on macos and linux, sys_get_temp_dir() is used as fallback.
at line 145
static array
glob(string $pattern, int $flags = 0)
A wrapper for PHP's built-in glob function.
This method always returns an array, even though glob() returns false on some systems instead of empty arrays.
at line 169
static array
globGrep(string $pattern, string $regex, int $flags = 0)
Find files by using the glob() method and filter the resulting array by a regex pattern.
Note that this method should basically replace the usage of GLOB_BRACE to be fully compatible to systems where this constant is not defined. Instead of a glob pattern like "/path/.{jpg,png}" it is more safe to use a generic pattern like "/path/.*" filtered by a regex like "/.(jpg|png)$/i" without using the GLOB_BRACE flag.
at line 183
static bool
isAllowedFileType(string $str)
Tests if a string is a file name with an allowed file extension.
Basically a possibly existing file extension is checked against the array of allowed file extensions.
"/url/file.jpg" will return true, "/url/file" or "/url/file.something" will return false.
at line 206
static bool
makeDir(string $path)
Create directory if not existing.
at line 223
static string
normalizeSlashes(string $path)
Replace all backslashes in a given path with forward slashes.
at line 234
static bool
write(string $file, string $content)
Write content to a file and create the parent directory if needed.