Files
abstract class Files (View source)
File and directory functions
Properties
static protected array | $sizeUnits | Supported file size units for the byte conversion functions below |
Methods
Replacing backslashes and double slashes to slashes.
Makes sure path has a trailing slash
Properly glues together filepaths / filenames by replacing backslashes and double slashes of the specified paths.
Returns all filenames from the specified directory. Filters hidden files and directories.
No description
Deletes all files, directories and subdirectories from the specified directory. The passed directory itself won't be deleted though.
Removes all empty directories on the specified path. If a base path is given, this function will not remove directories, even if empty, above and including that base path.
Deletes all files, directories and subdirectories from the specified directory. Contrary to emptyDirectoryRecursively() this function will also finally remove the emptied directory.
Creates a directory specified by $path. If the parent directories don't exist yet, they will be created as well.
Copies the contents of the source directory to the target directory.
An enhanced version of file_get_contents which intercepts the warning issued by the original function if a file could not be loaded.
Returns a human-readable message for the given PHP file upload error constant.
A version of is_link() that works on Windows too
A version of unlink() that works on Windows regardless on the symlink type (file/directory).
Converts an integer with a byte count into human-readable form
Converts a size string (e.g. "1024.0 MB") to the number of bytes it represents
Will create relative symlinks by given absolute paths, falling back to Windows' mklink command because PHP's symlink() does not support relative paths there.
Finds the relative path between two given absolute paths.
Details
static string
getUnixStylePath(string $path)
Replacing backslashes and double slashes to slashes.
It's needed to compare paths (especially on windows).
static string
getNormalizedPath(string $path)
Makes sure path has a trailing slash
static string
concatenatePaths(array $paths)
Properly glues together filepaths / filenames by replacing backslashes and double slashes of the specified paths.
Note: trailing slashes will be removed, leading slashes won't. Usage: concatenatePaths(array('dir1/dir2', 'dir3', 'file'))
static array
readDirectoryRecursively(string $path, string $suffix = null, bool $returnRealPath = false, bool $returnDotFiles = false)
Returns all filenames from the specified directory. Filters hidden files and directories.
static Generator
getRecursiveDirectoryGenerator(string $path, string $suffix = null, bool $returnRealPath = false, bool $returnDotFiles = false)
No description
static void
emptyDirectoryRecursively(string $path)
Deletes all files, directories and subdirectories from the specified directory. The passed directory itself won't be deleted though.
static void
removeEmptyDirectoriesOnPath(string $path, string $basePath = null)
Removes all empty directories on the specified path. If a base path is given, this function will not remove directories, even if empty, above and including that base path.
Any .DS_Store files are silently removed.
static void
removeDirectoryRecursively(string $path)
Deletes all files, directories and subdirectories from the specified directory. Contrary to emptyDirectoryRecursively() this function will also finally remove the emptied directory.
static void
createDirectoryRecursively(string $path)
Creates a directory specified by $path. If the parent directories don't exist yet, they will be created as well.
static void
copyDirectoryRecursively(string $sourceDirectory, string $targetDirectory, bool $keepExistingFiles = false, bool $copyDotFiles = false)
Copies the contents of the source directory to the target directory.
$targetDirectory will be created if it does not exist.
If $keepExistingFiles is true, this will keep files already present in the target location. It defaults to false.
If $copyDotFiles is true, this will copy files whose name begin with a dot. It defaults to false.
static mixed
getFileContents(string $pathAndFilename, int $flags = 0, resource $context = null, int $offset = 0, int $maximumLength = -1)
An enhanced version of file_get_contents which intercepts the warning issued by the original function if a file could not be loaded.
static string
getUploadErrorMessage(int $errorCode)
Returns a human-readable message for the given PHP file upload error constant.
static bool
is_link(string $pathAndFilename)
A version of is_link() that works on Windows too
static bool
unlink(string $pathAndFilename)
A version of unlink() that works on Windows regardless on the symlink type (file/directory).
If this method could not unlink the specified file or it doesn't exist anymore (e.g. because of a concurrent deletion), it will clear the stat cache for its filename and check if the file still exist. If it does not exist, this method assumes that the file has been deleted by another process and will return true. If the file still exists though, this method will return false.
static string
bytesToSizeString(float|int $bytes, int $decimals = null, string $decimalSeparator = null, string $thousandsSeparator = null)
Converts an integer with a byte count into human-readable form
static float
sizeStringToBytes(string $sizeString)
Converts a size string (e.g. "1024.0 MB") to the number of bytes it represents
static bool
createRelativeSymlink(string $target, string $link)
Will create relative symlinks by given absolute paths, falling back to Windows' mklink command because PHP's symlink() does not support relative paths there.
If the file exists already, it will be deleted regardless of its attributes.
static string
getRelativePath(string $from, string $to)
Finds the relative path between two given absolute paths.
Credits go to stackoverflow member "Gordon".