laminas/laminas-validator
Laminas Validator provides flexible, reusable validation rules for PHP applications. Includes built-in validators, input filtering/validation chains, and tools for validating common data types like emails, URLs, numbers, strings, and more.
Laminas\Validator\File\Exists checks for the existence of files in specified
directories.
This validator is inversely related to the NotExists validator.
The following set of options are supported:
directory: Array of directories, or comma-delimited string of directories.all: A boolean that when true (default) requires that the filename is present in all the listed directoriesuse Laminas\Validator\File\Exists;
// Only allow files that exist in ~both~ directories
$validator = new Exists(['directory' => '/tmp,/var/tmp']);
if ($validator->isValid('myfile.txt')) {
// file is present in all directories
} else {
// file was not present in at least 1 of the directories
}
use Laminas\Validator\File\Exists;
// Allow files that exist in any of the listed directories
$validator = new Exists([
'directory' => ['/tmp', '/var/tmp'],
'all' => false,
]);
if ($validator->isValid('myfile.txt')) {
// file was found in at least 1 directory
} else {
// file was not found in one of the directories
}
use Laminas\Validator\File\Exists;
// Check the value for existence without a directory option
$validator = new Exists();
if ($validator->isValid('/path/to/myfile.txt')) {
// file exists
}
Checks against All Directories
By default, this validator checks whether the specified file exists in all of the given directories; validation will fail if the file does not exist in one or more of them. To change this behaviour, be sure to set the
alloption to false.
This validator accepts and validates 3 types of argument:
$_FILES superglobalUploadedFileInterface instanceWithout a directory option, the validator will check any of the listed argument types to ensure they exist.
For example, without a directory option, any successful upload will be deemed valid.
How can I help you explore Laravel packages today?