Documentation

File
in package

Tool class for the field type `File`.

Table of Contents

TABLE_NAME_TEMP  = 'u_#__file_upload_temp'
$allowedFormats  : array<string|int, mixed>
Allowed formats.
$validateError  : string
Last validate error.
$content  : string
File content.
$error  : bool|int
Error code.
$ext  : string
File extension.
$mimeShortType  : string
File short mime type.
$mimeType  : string
File mime type.
$mimeTypes  : array<string|int, string>
Mime types.
$name  : string
File name.
$path  : string
File path.
$phpInjection  : array<string|int, string>
What file types to validate by php injection.
$size  : int
Size.
$tmpPath  : string
Directory path used for temporary files.
$validateAllCodeInjection  : bool
Validate all files by code injection.
cleanTemp()  : int
Delete data from the temporary table.
createTempFile()  : string
Creates a temporary file.
delete()  : bool
Delete file.
deleteForRecord()  : mixed
Delete files from record.
generateHash()  : string
Generate file hash.
getContents()  : string
Get file ontent.
getDirectoryPath()  : string
Get directory path.
getEncoding()  : string
Get file encoding.
getErrorMessage()  : string
Get error message by code.
getExtension()  : string
Get file extension.
getImageBaseData()  : string
Get image base data.
getLocalPath()  : string
Get crm pathname or relative path.
getMimeContentType()  : string
Get mime content type ex. image/png.
getMimeType()  : string
Get mime type.
getName()  : string
Get file name.
getPath()  : string
Get file path.
getSanitizeName()  : string
Function to sanitize the upload file name when the file name is detected to have bad extensions.
getShortMimeType()  : string
Get short mime type.
getSize()  : int
Get size.
getTmpPath()  : string
Get temporary directory path.
getUploadFile()  : array<string|int, mixed>
Get upload file details from db.
initMimeTypes()  : mixed
Init mime types.
initStorage()  : string
Init storage diractory.
initStorageFileDirectory()  : string
Init storage file directory.
insertMediaFile()  : int
Add an entry to the media table of files.
insertTempFile()  : int
Add an entry to the temporary table of files.
isAllowedDirectory()  : bool
Check is it an allowed directory.
isAllowedFileDirectory()  : bool
Check is it an allowed file directory.
isDirWriteable()  : bool
Check if given directory is writeable.
isExistsUrl()  : bool
Check if give URL exists.
isWriteable()  : bool
Check if give path is writeable.
loadFromBase()  : self|null
Load file instance from base string.
loadFromContent()  : bool|self
Load file instance from content.
loadFromInfo()  : self
Load file instance from file info.
loadFromPath()  : self
Load file instance from file path.
loadFromRequest()  : self
Load file instance from request.
loadFromUrl()  : self|bool
Load file instance from url.
moveFile()  : bool
Move file.
parse()  : array<string|int, mixed>
Parse.
sanitizeFileNameFromUrl()  : string
Function to get base name of file.
sanitizeUploadFileName()  : string
Function to sanitize the upload file name when the file name is detected to have bad extensions.
saveFromContent()  : array<string|int, mixed>|bool
Create document from content.
saveFromString()  : bool|self
Create document from string.
saveFromUrl()  : array<string|int, mixed>|bool
Create document from url.
secureFile()  : bool
Secure image file.
transform()  : array<string|int, mixed>
Transform mulitiple uploaded file information into useful format.
validate()  : bool
Validate whether the file is safe.
validateAndSecure()  : bool
Validate and secure the file.
validateImageContent()  : bool
Validate image content.
checkFile()  : mixed
Basic check file.
searchCodeInjection()  : bool
Search code injection in content.
validateCodeInjection()  : mixed
Validate code injection.
validateCodeInjectionInMetadata()  : mixed
Validate code injection in metadata.
validateFormat()  : mixed
Validate format.
validateImage()  : mixed
Validate image.
validateInjection()  : bool
Validate injection.

Constants

TABLE_NAME_TEMP

public string TABLE_NAME_TEMP = 'u_#__file_upload_temp'

Temporary table name.

Properties

$allowedFormats

Allowed formats.

public static array<string|int, mixed> $allowedFormats = ['image' => ['jpeg', 'png', 'jpg', 'pjpeg', 'x-png', 'gif', 'bmp', 'x-ms-bmp', 'webp']]

$validateError

Last validate error.

public string $validateError = ''

$content

File content.

private string $content

$error

Error code.

private bool|int $error = false

$ext

File extension.

private string $ext

$mimeShortType

File short mime type.

private string $mimeShortType

$mimeType

File mime type.

private string $mimeType

$mimeTypes

Mime types.

private static array<string|int, string> $mimeTypes

$name

File name.

private string $name

$path

File path.

private string $path

$phpInjection

What file types to validate by php injection.

private static array<string|int, string> $phpInjection = ['image']

$size

Size.

private int $size

$tmpPath

Directory path used for temporary files.

private static string $tmpPath

$validateAllCodeInjection

Validate all files by code injection.

private bool $validateAllCodeInjection = false

Methods

cleanTemp()

Delete data from the temporary table.

public static cleanTemp(string|array<string|int, string> $keys) : int
Parameters
$keys : string|array<string|int, string>
Return values
int

createTempFile()

Creates a temporary file.

public static createTempFile([string $prefix = '' ][, string $ext = 'tmp' ]) : string
Parameters
$prefix : string = ''

The prefix of the generated temporary filename Note: Windows uses only the first three characters of prefix

$ext : string = 'tmp'

File extension, default: .tmp

Return values
string

The new temporary filename (with path), or throw an exception on failure

delete()

Delete file.

public delete() : bool
Return values
bool

generateHash()

Generate file hash.

public generateHash([bool $checkInAttachments = false ][, string $uploadFilePath = '' ]) : string
Parameters
$checkInAttachments : bool = false
$uploadFilePath : string = ''
Return values
string

File hash sha256

getContents()

Get file ontent.

public getContents() : string
Return values
string

getDirectoryPath()

Get directory path.

public getDirectoryPath() : string
Return values
string

getEncoding()

Get file encoding.

public getEncoding([array<string|int, mixed>|null $list = null ]) : string
Parameters
$list : array<string|int, mixed>|null = null
Return values
string

getErrorMessage()

Get error message by code.

public static getErrorMessage(int $code) : string
Parameters
$code : int
Return values
string

getExtension()

Get file extension.

public getExtension([mixed $fromName = false ]) : string
Parameters
$fromName : mixed = false
Return values
string

getImageBaseData()

Get image base data.

public static getImageBaseData(string $path) : string
Parameters
$path : string
Return values
string

getLocalPath()

Get crm pathname or relative path.

public static getLocalPath(string $path[, string $pathToTrim = ROOT_DIRECTORY ]) : string
Parameters
$path : string

Absolute pathname

$pathToTrim : string = ROOT_DIRECTORY

Path to trim

Return values
string

Local pathname

getMimeContentType()

Get mime content type ex. image/png.

public static getMimeContentType(string $fileName) : string
Parameters
$fileName : string
Return values
string

getMimeType()

Get mime type.

public getMimeType() : string
Return values
string

getName()

Get file name.

public getName([bool $decode = false ]) : string
Parameters
$decode : bool = false
Return values
string

getPath()

Get file path.

public getPath() : string
Return values
string

getSanitizeName()

Function to sanitize the upload file name when the file name is detected to have bad extensions.

public getSanitizeName() : string
Return values
string

getShortMimeType()

Get short mime type.

public getShortMimeType([int $type = 1 ]) : string
Parameters
$type : int = 1

0 or 1

Return values
string

getSize()

Get size.

public getSize() : int
Return values
int

getTmpPath()

Get temporary directory path.

public static getTmpPath() : string
Return values
string

getUploadFile()

Get upload file details from db.

public static getUploadFile(string $key) : array<string|int, mixed>
Parameters
$key : string
Return values
array<string|int, mixed>

initMimeTypes()

Init mime types.

public static initMimeTypes() : mixed
Return values
mixed

initStorage()

Init storage diractory.

public static initStorage(string $path) : string
Parameters
$path : string
Return values
string

initStorageFileDirectory()

Init storage file directory.

public static initStorageFileDirectory([string $suffix = false ]) : string
Parameters
$suffix : string = false
Return values
string

insertMediaFile()

Add an entry to the media table of files.

public insertMediaFile(array<string|int, mixed> $params) : int
Parameters
$params : array<string|int, mixed>
Return values
int

insertTempFile()

Add an entry to the temporary table of files.

public insertTempFile(array<string|int, mixed> $params) : int
Parameters
$params : array<string|int, mixed>
Return values
int

isAllowedDirectory()

Check is it an allowed directory.

public static isAllowedDirectory(string $fullPath) : bool
Parameters
$fullPath : string
Return values
bool

isAllowedFileDirectory()

Check is it an allowed file directory.

public static isAllowedFileDirectory(string $fullPath) : bool
Parameters
$fullPath : string
Return values
bool

isDirWriteable()

Check if given directory is writeable.

public static isDirWriteable(string $dirPath) : bool

NOTE: The check is made by trying to create a random file in the directory.

Parameters
$dirPath : string
Return values
bool

isExistsUrl()

Check if give URL exists.

public static isExistsUrl(string $url) : bool
Parameters
$url : string
Return values
bool

isWriteable()

Check if give path is writeable.

public static isWriteable(string $path[, bool $absolutePaths = false ]) : bool
Parameters
$path : string
$absolutePaths : bool = false
Return values
bool

loadFromBase()

Load file instance from base string.

public static loadFromBase(string $contents[, array<string|int, mixed> $param = [] ]) : self|null
Parameters
$contents : string
$param : array<string|int, mixed> = []
Return values
self|null

loadFromContent()

Load file instance from content.

public static loadFromContent(string $contents[, string $name = false ][, array<string|int, string> $param = [] ]) : bool|self
Parameters
$contents : string
$name : string = false
$param : array<string|int, string> = []
Return values
bool|self

loadFromInfo()

Load file instance from file info.

public static loadFromInfo(array<string|int, mixed> $fileInfo) : self
Parameters
$fileInfo : array<string|int, mixed>
Return values
self

loadFromPath()

Load file instance from file path.

public static loadFromPath(string $path) : self
Parameters
$path : string
Return values
self

loadFromRequest()

Load file instance from request.

public static loadFromRequest(array<string|int, mixed> $file) : self
Parameters
$file : array<string|int, mixed>
Return values
self

loadFromUrl()

Load file instance from url.

public static loadFromUrl(string $url[, array<string|int, string> $param = [] ]) : self|bool
Parameters
$url : string
$param : array<string|int, string> = []
Return values
self|bool

moveFile()

Move file.

public moveFile(string $target) : bool
Parameters
$target : string
Return values
bool

parse()

Parse.

public static parse(array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
$value : array<string|int, mixed>
Return values
array<string|int, mixed>

sanitizeFileNameFromUrl()

Function to get base name of file.

public static sanitizeFileNameFromUrl(string $url) : string
Parameters
$url : string
Return values
string

sanitizeUploadFileName()

Function to sanitize the upload file name when the file name is detected to have bad extensions.

public static sanitizeUploadFileName(string $fileName[, bool|string $badFileExtensions = false ]) : string
Parameters
$fileName : string

File name to be sanitized

$badFileExtensions : bool|string = false
Return values
string

saveFromContent()

Create document from content.

public static saveFromContent(self $file[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|bool
Parameters
$file : self
$params : array<string|int, mixed> = []
Tags
throws
Exception
Return values
array<string|int, mixed>|bool

saveFromString()

Create document from string.

public static saveFromString(string $contents[, array<string|int, mixed> $param = [] ]) : bool|self
Parameters
$contents : string
$param : array<string|int, mixed> = []
Return values
bool|self

saveFromUrl()

Create document from url.

public static saveFromUrl(string $url[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|bool
Parameters
$url : string

Url

$params : array<string|int, mixed> = []
Return values
array<string|int, mixed>|bool

secureFile()

Secure image file.

public static secureFile(File $file) : bool
Parameters
$file : File
Return values
bool

transform()

Transform mulitiple uploaded file information into useful format.

public static transform(array<string|int, mixed> $files[, bool $top = true ]) : array<string|int, mixed>
Parameters
$files : array<string|int, mixed>

$_FILES

$top : bool = true
Return values
array<string|int, mixed>

validate()

Validate whether the file is safe.

public validate([string|null $type = null ]) : bool
Parameters
$type : string|null = null
Tags
throws
Exception
Return values
bool

validateAndSecure()

Validate and secure the file.

public validateAndSecure([string|null $type = null ]) : bool
Parameters
$type : string|null = null
Return values
bool

validateImageContent()

Validate image content.

public validateImageContent() : bool
Tags
throws
DangerousFile
Return values
bool

checkFile()

Basic check file.

private checkFile() : mixed
Tags
throws
Exception
Return values
mixed

searchCodeInjection()

Search code injection in content.

private searchCodeInjection() : bool
Return values
bool

validateCodeInjection()

Validate code injection.

private validateCodeInjection() : mixed
Tags
throws
Exception
Return values
mixed

validateCodeInjectionInMetadata()

Validate code injection in metadata.

private validateCodeInjectionInMetadata() : mixed
Tags
throws
DangerousFile
Return values
mixed

validateFormat()

Validate format.

private validateFormat() : mixed
Tags
throws
Exception
Return values
mixed

validateImage()

Validate image.

private validateImage() : mixed
Tags
throws
Exception
Return values
mixed

validateInjection()

Validate injection.

private validateInjection(string|array<string|int, mixed> $data) : bool
Parameters
$data : string|array<string|int, mixed>
Return values
bool

        

Search results