Documentation

File
in package

File class.

Tags
copyright

YetiForce Sp. z o.o

license

YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)

author

Mariusz Krzaczkowski m.krzaczkowski@yetiforce.com

author

Radosław Skrzypczak r.skrzypczak@yetiforce.com

Table of Contents

TABLE_NAME_TEMP  = 'u_#__file_upload_temp'
Temporary table name.
$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.
$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.
checkFilePath()  : bool
CheckFilePath.
cleanTemp()  : int
Delete data from the temporary table.
delete()  : bool
Delete file.
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.
initStorageFileDirectory()  : string
Init storage file directory.
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.
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.
saveFromBase()  : array<string|int, mixed>
Save file from base64 encoded string.
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.
saveImageFromUrl()  : array<string|int, mixed>
Save file from given url.
secureImage()  : bool
Secure image file.
transform()  : array<string|int, mixed>
Transform mulitiple uploaded file information into useful format.
updateUploadFiles()  : array<string|int, mixed>
Update upload files.
uploadAndSave()  : array<string|int, mixed>
Upload and save attachment.
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.
validateImageMetadata()  : bool
Validate image metadata.

Constants

TABLE_NAME_TEMP

Temporary table name.

public mixed TABLE_NAME_TEMP = 'u_#__file_upload_temp'

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

$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

checkFilePath()

CheckFilePath.

public static checkFilePath(string $path) : bool
Parameters
$path : string
Return values
bool

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

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() : string
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

initStorageFileDirectory()

Init storage file directory.

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

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

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(array<string|int, mixed> $path) : self
Parameters
$path : array<string|int, mixed>
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

saveFromBase()

Save file from base64 encoded string.

public static saveFromBase(string $raw, string $moduleName) : array<string|int, mixed>
Parameters
$raw : string

base64 string

$moduleName : string

Destination record module name

Return values
array<string|int, mixed>

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

saveImageFromUrl()

Save file from given url.

public static saveImageFromUrl(string $url, string $moduleName[, string|bool $type = false ]) : array<string|int, mixed>
Parameters
$url : string
$moduleName : string
$type : string|bool = false
Return values
array<string|int, mixed>

secureImage()

Secure image file.

public static secureImage(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>

updateUploadFiles()

Update upload files.

public static updateUploadFiles(array<string|int, mixed> $value, Vtiger_Record_Model $recordModel, Vtiger_Field_Model $fieldModel) : array<string|int, mixed>
Parameters
$value : array<string|int, mixed>
$recordModel : Vtiger_Record_Model
$fieldModel : Vtiger_Field_Model
Return values
array<string|int, mixed>

uploadAndSave()

Upload and save attachment.

public static uploadAndSave(Request $request, array<string|int, mixed> $files, string $type, string $storageName) : array<string|int, mixed>
Parameters
$request : Request
$files : array<string|int, mixed>
$type : string
$storageName : string
Tags
throws
IllegalValue
throws
Exception
throws
Exception
Return values
array<string|int, mixed>

validate()

Validate whether the file is safe.

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

validateAndSecure()

Validate and secure the file.

public validateAndSecure([bool|string $type = false ]) : bool
Parameters
$type : bool|string = false
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

validateImageMetadata()

Validate image metadata.

private validateImageMetadata(mixed $data) : bool
Parameters
$data : mixed
Return values
bool

Search results