Documentation

Extension extends Base
in package

Validate File Extension

This class validates an uploads file extension. It takes file extension with out dot or array of extensions. For example: 'png' or array('jpg', 'png', 'gif').

WARING! Validation only by file extension not very secure.

Tags
author

Alex Kucherenko kucherenko.email@gmail.com

Table of Contents

Properties

$allowedExtensions  : array<string|int, mixed>
Array of cceptable file extensions without leading dots
$message  : string
Error message

Methods

__construct()  : mixed
Constructor
getMessage()  : string
Get error message
setMessage()  : mixed
Set error message
validate()  : bool
Validate

Properties

$allowedExtensions

Array of cceptable file extensions without leading dots

protected array<string|int, mixed> $allowedExtensions

$message

Error message

protected string $message = 'Invalid file extension. Must be one of: %s'

Methods

__construct()

Constructor

public __construct(string|array<string|int, mixed> $allowedExtensions) : mixed
Parameters
$allowedExtensions : string|array<string|int, mixed>

Allowed file extensions

Tags
example

new \Upload\Validation\Extension(array('png','jpg','gif'))

example

new \Upload\Validation\Extension('png')

getMessage()

Get error message

public getMessage() : string
Return values
string

setMessage()

Set error message

public setMessage(string $message) : mixed
Parameters
$message : string

validate()

Validate

public validate(File $file) : bool
Parameters
$file : File
Return values
bool
✖ Error 404 while fetching file: ✖ Error 404 while fetching file: 
On this page

Search results