FILE VALIDATION

Learn how you can validate a file using this library

This validation falls under the group "Attributes Validation", and it follows the syntax below.

//syntax
$valRules = array(
"FORM_INPUT_NAME" => array(
["ATTRIBUTE_TITLE", "VALUE", "CUSTOM_ERROR_MESSAGE"]
)
);

FILE VALIDATION RULES

ACCEPT

Use this rule to list out the file extensions allowed for upload.

POSSIBLE VALUES

.png, .jpg, .jpeg

We recommend that you use ACCEPT-MIME rule to check for the file MIME types of selected files, because an end user can rename any file to have an extension outside its original file type.


ACCEPT-MIME

Use this rule to list out the file MIME types allowed for upload. This rule also supports MIME types with wildcards.

POSSIBLE VALUES

image/png, image/jpg, image/jpeg

POSSIBLE VALUES

image/*, audio/*

SIZE

Use this rule to validate the selected file(s) size. If you provide 5MB, it means that the file uploaded by the user must be 5MB in size.

POSSIBLE VALUE

10MB


MINSIZE

Use this rule to validate the minimum size of the selected file(s). If you provide 5MB, it means that the file uploaded by the user must be 5MB in size or more.

POSSIBLE VALUE

10MB


MAXSIZE

Use this rule to validate the maximum size of the selected file(s). If you provide 5MB, it means that the file uploaded by the user must be 5MB in size or less.

POSSIBLE VALUES

10GB

Note that the digital storage supported, ranges from bytes up to petabytes.


FILES

Use this attribute to check the number of files selected by the user. If you provide 5, it means that the user must select 5 files.

This rule is only supported in multiple file upload.

POSSIBLE VALUES

5


MINFILES

Use this attribute to check the minimum number of files selected by the user. If you provide 5, it means that the user must select 5 files or more.

This rule is only supported in multiple file upload.

POSSIBLE VALUES

10


MAXFILES

Use this attribute to check the maximum number of files selected by the user. If you provide 5, it means that the user must select 5 files or less.

This rule is only supported in multiple file upload.

POSSIBLE VALUES

20

Rule Title Possible value(s)
ACCEPT .png, .jpg, .jpeg
ACCEPT-MIME image/png, image/jpg, image/jpeg, audio/*
SIZE 5MB
MINSIZE 10GB
MAXSIZE 10PB
FILES 5
MINFILES 10
MAXFILES 30

Follow the syntax below to define a validation rule for file upload.

//syntax
$valRules = array(
"FORM_INPUT_NAME" => array(
["RULE_TITLE", "VALUE", "CUSTOM_ERROR_MESSAGE"]
)
);
//sample Validation
$valRules = array(
"profile" => array(
["R", "Your profile picture is required"],
["MAXSIZE", "2MB", "Your profile must be 2MB or less"],
["ACCEPT-MIME", "image/png, image/jpg, image/jpeg", "Image File type is not supported!"]
)
);
//begin validation on $_FILES array
$myForm->validateFiles($valRules)

You have validated a form and there are Validation errors, how do you handle these errors?

Learn more
DEMO FORM