UploadValidator
in package
Table of Contents
Properties
Methods
- __construct() : mixed
- UploadValidator constructor.
- getError() : string|null
- Check uploaded file size
- redirectOnError() : mixed
- Check uploaded file size. Redirects to the specified URL on failure.
- renderJsonOnError() : mixed
- Check uploaded file size. Renders JSON on failure.
- setFiles() : void
- Sets the files property of the UploadValidator instance.
- setPost() : void
- Sets the post property of the UploadValidator instance.
Properties
$files
private
array<string, mixed>
$files
HTTP File Upload variables
$post
private
array<string, mixed>
$post
HTTP POST variables
Methods
__construct()
UploadValidator constructor.
public
__construct([array<string|int, mixed>|null $post = null ][, array<string|int, mixed>|null $files = null ]) : mixed
Parameters
- $post : array<string|int, mixed>|null = null
-
HTTP POST variables. If null, $_POST is used.
- $files : array<string|int, mixed>|null = null
-
HTTP File Upload variables. If null, $_FILES is used.
getError()
Check uploaded file size
public
getError(string $fileName[, mixed $customMaxSize = null ]) : string|null
Parameters
- $fileName : string
-
the name of the posted file
- $customMaxSize : mixed = null
-
maximum file upload size
Return values
string|null —the error message or null if all checks are ok
redirectOnError()
Check uploaded file size. Redirects to the specified URL on failure.
public
redirectOnError(string $fileName, mixed $redirectUrl[, mixed $customMaxSize = null ]) : mixed
Parameters
- $fileName : string
-
the name of the posted file
- $redirectUrl : mixed
-
the URL to redirect on failure
- $customMaxSize : mixed = null
-
maximum file upload size
renderJsonOnError()
Check uploaded file size. Renders JSON on failure.
public
renderJsonOnError(string $fileName[, array<string|int, mixed> $debugInfo = [] ][, mixed $customMaxSize = null ]) : mixed
Parameters
- $fileName : string
-
the name of the posted file
- $debugInfo : array<string|int, mixed> = []
-
the URL to redirect on failure
- $customMaxSize : mixed = null
-
maximum file upload size
setFiles()
Sets the files property of the UploadValidator instance.
public
setFiles(array<string|int, mixed> $files) : void
This method allows for updating the files array after the object has been instantiated. It's useful for testing or when file data needs to be modified after initial creation.
Parameters
- $files : array<string|int, mixed>
-
An associative array of uploaded file information, typically in the format of $_FILES. Each element should contain file details like name, type, size, tmp_name, and error.
Return values
void —This method does not return a value.
setPost()
Sets the post property of the UploadValidator instance.
public
setPost(array<string|int, mixed> $post) : void
This method allows for updating the post array after the object has been instantiated. It's useful for testing or when post data needs to be modified after initial creation.
Parameters
- $post : array<string|int, mixed>
-
An associative array of POST data, typically in the format of $_POST. This array contains key-value pairs of form data submitted via HTTP POST.
Return values
void —This method does not return a value.