Does the given file/link/dir exist?
Thie method accepts an $options
argument that can be specified as an array
or a string (space or comma separated). The examples here demonstrate usage as
a string since it is the simplest for readability.
- This function may return false for symlinks pointing to non-existing files, unless you specify
link
as thetype
. - Specifying
false
for thereadable
orwritable
argument disables the option from being used, it doesn’t perform a NOT condition. - The
writable
option may also be written aswriteable
, if preferred.
Available since version 3.0.180.
Example
// 1. check if exists
$exists = $files->exists('/path/file.ext');
// 2. check if exists and is readable (or writable)
$exists = $files->exists('/path/file.ext', 'readable');
$exists = $files->exists('/path/file.ext', 'writable');
// 3. check if exists and is file, link or dir
$exists = $files->exists('/path/file.ext', 'file');
$exists = $files->exists('/path/file.ext', 'link');
$exists = $files->exists('/path/file.ext', 'dir');
// 4. check if exists and is writable file or dir
$exists = $files->exists('/path/file.ext', 'writable file');
$exists = $files->exists('/path/dir/', 'writable dir');
// 5. check if exists and is readable and writable file
$exists = $files->exists('/path/file.ext', 'readable writable file');
Usage
// basic usage
$bool = $files->exists(string $filename);
// usage with all arguments
$bool = $files->exists(string $filename, $options = '');
Arguments
Name | Type(s) | Description |
---|---|---|
filename | string | |
options (optional) | array, string | Can be specified as array or string:
|
Return value
bool
Exceptions
Method can throw exceptions on error:
WireException
- if given invalid or unrecognized $options
API reference based on ProcessWire core version 3.0.236