class FileUpload (View source)

This class is used to manage file upload using ajax

Properties

array{script_url: string, upload_dir: string, upload_url: string, param_name: string, delete_type: string, max_file_size: ?int, min_file_size: int, accept_file_types: string, max_number_of_files: ?int, max_width: ?int, max_height: ?int, min_width: int, min_height: int, discard_aborted_uploads: bool, image_versions: array<string, array{upload_dir: string, upload_url: string, max_width: int, max_height: int, jpeg_quality?: int}>} $options
protected int $fk_element
protected string $element

Methods

__construct(?array{script_url?: string, upload_dir?: string, upload_url?: string, param_name?: string, delete_type?: string, max_file_size?: ?int, min_file_size?: int, accept_file_types?: string, max_number_of_files?: ?int, max_width?: ?int, max_height?: ?int, min_width?: int, min_height?: int, discard_aborted_uploads?: bool, image_versions?: array<string, array{upload_dir?: string, upload_url?: string, max_width?: int, max_height?: int, jpeg_quality?: int}>} $options = null, int $fk_element = null, string $element = null)

Constructor.

string
getFullUrl()

Return full URL

void
setFileDeleteUrl(stdClass $file)

Set delete url

stdClass
getFileObject(string $file_name)

getFileObject

stdClass>
getFileObjects()

getFileObjects

createScaledImage($file_name, array{upload_dir: string} $options)

Create thumbs of a file uploaded.

bool
validate(string $uploaded_file, object $file, string $error, string $index)

Make validation on an uploaded file

string
upcountNameCallback(int $matches)

Enter description here .

string
upcountName(string $name)

Enter description here .

string
trimFileName(string $name, string $type, string $index)

trimFileName

stdClass|null
handleFileUpload(string $uploaded_file, string $name, int $size, string $type, string $error, string $index)

handleFileUpload.

int
post()

Output data

Details

__construct(?array{script_url?: string, upload_dir?: string, upload_url?: string, param_name?: string, delete_type?: string, max_file_size?: ?int, min_file_size?: int, accept_file_types?: string, max_number_of_files?: ?int, max_width?: ?int, max_height?: ?int, min_width?: int, min_height?: int, discard_aborted_uploads?: bool, image_versions?: array<string, array{upload_dir?: string, upload_url?: string, max_width?: int, max_height?: int, jpeg_quality?: int}>} $options = null, int $fk_element = null, string $element = null)

Constructor.

This set ->$options

Parameters

?array{script_url?: string, upload_dir?: string, upload_url?: string, param_name?: string, delete_type?: string, max_file_size?: ?int, min_file_size?: int, accept_file_types?: string, max_number_of_files?: ?int, max_width?: ?int, max_height?: ?int, min_width?: int, min_height?: int, discard_aborted_uploads?: bool, image_versions?: array<string, array{upload_dir?: string, upload_url?: string, max_width?: int, max_height?: int, jpeg_quality?: int}>} $options

Options array

int $fk_element

ID of element

string $element

Code of element

protected string getFullUrl()

Return full URL

Return Value

string URL

protected void setFileDeleteUrl(stdClass $file)

Set delete url

Parameters

stdClass $file

File object (see getFileObject)

Return Value

void

protected stdClass getFileObject(string $file_name)

getFileObject

Parameters

string $file_name Filename

Return Value

stdClass

protected stdClass> getFileObjects()

getFileObjects

Return Value

stdClass>

Array of objects

protected createScaledImage($file_name, array{upload_dir: string} $options)

Create thumbs of a file uploaded.

@param string $file_name Filename

Parameters

$file_name
array{upload_dir: string} $options

is array('max_width', 'max_height') @return bool

protected bool validate(string $uploaded_file, object $file, string $error, string $index)

Make validation on an uploaded file

Parameters

string $uploaded_file

Upload file

object $file File
string $error Error
string $index Index

Return Value

bool

True if OK, False if KO

protected string upcountNameCallback(int $matches)

Enter description here .

..

Parameters

int $matches ???

Return Value

string ???

protected string upcountName(string $name)

Enter description here .

..

Parameters

string $name ???

Return Value

string ???

protected string trimFileName(string $name, string $type, string $index)

trimFileName

Parameters

string $name Filename
string $type ???
string $index ???

Return Value

string

protected stdClass|null handleFileUpload(string $uploaded_file, string $name, int $size, string $type, string $error, string $index)

handleFileUpload.

Validate data, move the uploaded file then create the thumbs if this is an image.

Parameters

string $uploaded_file

Upload file

string $name Name
int $size Size
string $type Type
string $error Error
string $index Index

Return Value

stdClass|null

See also

dol_add_file_process()

int post()

Output data

Return Value

int

0 if OK, nb of error if errors