Validation rules
By default, no validation rules are attached to the model. You must explicitly attach each rule if needed. Rules not referring to PHP upload errors are configurable but fallback to the behavior configuration.
isUnderPhpSizeLimit
Check that the file does not exceed the max file size specified by PHP
public $validate = [
'photo' => [
'rule' => 'isUnderPhpSizeLimit',
'message' => 'File exceeds upload filesize limit',
],
];isUnderFormSizeLimit
Check that the file does not exceed the max file size specified in the HTML Form
public $validate = [
'photo' => [
'rule' => 'isUnderFormSizeLimit',
'message' => 'File exceeds form upload filesize limit',
],
];isCompletedUpload
Check that the file was completely uploaded
public $validate = [
'photo' => [
'rule' => 'isCompletedUpload',
'message' => 'File was not successfully uploaded',
],
];isFileUpload
Check that a file was uploaded
public $validate = [
'photo' => [
'rule' => 'isFileUpload',
'message' => 'File was missing from submission',
],
];isFileUploadOrHasExistingValue
Check that either a file was uploaded, or the existing value in the database is not blank
public $validate = [
'photo' => [
'rule' => 'isFileUploadOrHasExistingValue',
'message' => 'File was missing from submission',
],
];tempDirExists
Check that the PHP temporary directory is missing
public $validate = [
'photo' => [
'rule' => 'tempDirExists',
'message' => 'The system temporary directory is missing',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['tempDirExists', false],
'message' => 'The system temporary directory is missing',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isSuccessfulWrite
Check that the file was successfully written to the server
public $validate = [
'photo' => [
'rule' => 'isSuccessfulWrite',
'message' => 'File was unsuccessfully written to the server',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isSuccessfulWrite', false],
'message' => 'File was unsuccessfully written to the server',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
noPhpExtensionErrors
Check that a PHP extension did not cause an error
public $validate = [
'photo' => [
'rule' => 'noPhpExtensionErrors',
'message' => 'File was not uploaded because of a faulty PHP extension',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['noPhpExtensionErrors', false],
'message' => 'File was not uploaded because of a faulty PHP extension',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isValidMimeType
Check that the file is of a valid mimetype
public $validate = [
'photo' => [
'rule' => ['isValidMimeType', ['application/pdf', 'image/png']],
'message' => 'File is not a pdf or png',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isValidMimeType', ['application/pdf', 'image/png'], false],
'message' => 'File is not a pdf or png',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isWritable
Check that the upload directory is writable
public $validate = [
'photo' => [
'rule' => ['isWritable'],
'message' => 'File upload directory was not writable',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isWritable', false],
'message' => 'File upload directory was not writable',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isValidDir
Check that the upload directory exists
public $validate = [
'photo' => [
'rule' => ['isValidDir'],
'message' => 'File upload directory does not exist',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isValidDir', false],
'message' => 'File upload directory does not exist',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isBelowMaxSize
Check that the file is below the maximum file upload size (checked in bytes)
public $validate = [
'photo' => [
'rule' => ['isBelowMaxSize', 1024],
'message' => 'File is larger than the maximum filesize',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isBelowMaxSize', 1024, false],
'message' => 'File is larger than the maximum filesize',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isAboveMinSize
Check that the file is above the minimum file upload size (checked in bytes)
public $validate = [
'photo' => [
'rule' => ['isAboveMinSize', 1024],
'message' => 'File is below the mimimum filesize',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isAboveMinSize', 1024, false],
'message' => 'File is below the mimimum filesize',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isValidExtension
Check that the file has a valid extension
public $validate = [
'photo' => [
'rule' => ['isValidExtension', ['pdf', 'png', 'txt']],
'message' => 'File does not have a pdf, png, or txt extension',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isValidExtension', ['pdf', 'png', 'txt'], false],
'message' => 'File does not have a pdf, png, or txt extension',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isAboveMinHeight
Check that the file is above the minimum height requirement (checked in pixels)
public $validate = [
'photo' => [
'rule' => ['isAboveMinHeight', 150],
'message' => 'File is below the minimum height',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isAboveMinHeight', 150, false],
'message' => 'File is below the minimum height',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isBelowMaxHeight
Check that the file is below the maximum height requirement (checked in pixels)
public $validate = [
'photo' => [
'rule' => ['isBelowMaxHeight', 150],
'message' => 'File is above the maximum height',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isBelowMaxHeight', 150, false],
'message' => 'File is above the maximum height',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isAboveMinWidth
Check that the file is above the minimum width requirement (checked in pixels)
public $validate = [
'photo' => [
'rule' => ['isAboveMinWidth', 150],
'message' => 'File is below the minimum width',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isAboveMinWidth', 150, false],
'message' => 'File is below the minimum width',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
isBelowMaxWidth
Check that the file is below the maximum width requirement (checked in pixels)
public $validate = [
'photo' => [
'rule' => ['isBelowMaxWidth', 150],
'message' => 'File is above the maximum width',
],
];If the argument $requireUpload is passed, we can skip this check when a file is not uploaded:
public $validate = [
'photo' => [
'rule' => ['isBelowMaxWidth', 150, false],
'message' => 'File is above the maximum width',
],
];In the above, the variable $requireUpload has a value of false. By default, requireUpload is set to true.
