dolibarr 25.0.0-alpha
FileUpload Class Reference

This class is used to manage file upload using ajax. More...

Public Member Functions

 __construct ($options=null, $fk_element=null, $element=null)
 Constructor.
 
 post ()
 Output data.
 

Protected Member Functions

 getFullUrl ()
 Return full URL.
 
 setFileDeleteUrl ($file)
 Set delete url.
 
 getFileObject ($file_name)
 getFileObject
 
 getFileObjects ()
 getFileObjects
 
 createScaledImage ($file_name, $options)
 Create thumbs of a file uploaded.
 
 validate ($uploaded_file, $file, $error, $index)
 Make validation on an uploaded file.
 
 upcountNameCallback ($matches)
 Enter description here ...
 
 upcountName ($name)
 Enter description here ...
 
 trimFileName ($name, $type, $index)
 trimFileName
 
 handleFileUpload ($uploaded_file, $name, $size, $type, $error, $index)
 handleFileUpload.
 

Detailed Description

This class is used to manage file upload using ajax.

Definition at line 36 of file fileupload.class.php.

Constructor & Destructor Documentation

◆ __construct()

FileUpload::__construct ( $options = null,
$fk_element = null,
$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_elementID of element
string$elementCode of element
Exceptions
ExceptionIf the object was not found, if the element does not support file uploading, or if the upload directory is missing or not writable

Definition at line 67 of file fileupload.class.php.

References dol_sanitizeFileName(), dol_sanitizePathName(), dol_syslog(), get_exdir(), getDolGlobalInt(), getElementProperties(), and getMultidirOutput().

Member Function Documentation

◆ createScaledImage()

FileUpload::createScaledImage ( $file_name,
$options )
protected

Create thumbs of a file uploaded.

Parameters
string$file_nameFilename
array{upload_dir:string}$options is array('max_width', 'max_height')
Returns
bool

Definition at line 307 of file fileupload.class.php.

References dol_mkdir(), and vignette().

Referenced by handleFileUpload().

◆ getFileObject()

FileUpload::getFileObject ( $file_name)
protected

getFileObject

Parameters
string$file_nameFilename
Returns
?stdClass

Definition at line 264 of file fileupload.class.php.

References dol_is_file(), dol_mimetype(), and setFileDeleteUrl().

◆ getFileObjects()

FileUpload::getFileObjects ( )
protected

getFileObjects

Returns
array<?stdClass> Array of objects

Definition at line 295 of file fileupload.class.php.

Referenced by validate().

◆ getFullUrl()

FileUpload::getFullUrl ( )
protected

Return full URL.

Returns
string URL

Definition at line 231 of file fileupload.class.php.

◆ handleFileUpload()

FileUpload::handleFileUpload ( $uploaded_file,
$name,
$size,
$type,
$error,
$index )
protected

handleFileUpload.

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

Parameters
string$uploaded_fileUpload file
string$nameName
int$sizeSize
string$typeType
string$errorError
string$indexIndex
Returns
stdClass|null
See also
dol_add_file_process()

Definition at line 466 of file fileupload.class.php.

References addFileIntoDatabaseIndex(), createScaledImage(), deleteFilesIntoDatabaseIndex(), dol_filesize(), dol_is_file(), dol_mimetype(), dol_mkdir(), dol_move_uploaded_file(), dol_sanitizeFileName(), dol_sanitizePathName(), dol_syslog(), dolChmod(), getDolGlobalString(), setFileDeleteUrl(), trimFileName(), upcountName(), and validate().

Referenced by post().

◆ post()

FileUpload::post ( )

Output data.

Returns
void Output data
int 0 if OK, nb of error if errors

Definition at line 608 of file fileupload.class.php.

References handleFileUpload().

◆ setFileDeleteUrl()

FileUpload::setFileDeleteUrl ( $file)
protected

Set delete url.

Parameters
stdClass$fileFile object (see getFileObject)
Returns
void

Definition at line 249 of file fileupload.class.php.

Referenced by getFileObject(), and handleFileUpload().

◆ trimFileName()

FileUpload::trimFileName ( $name,
$type,
$index )
protected

trimFileName

Parameters
string$nameFilename
string$type???
string$index???
Returns
string

Definition at line 434 of file fileupload.class.php.

References dol_is_file(), dol_sanitizeFileName(), and upcountName().

Referenced by handleFileUpload().

◆ upcountName()

FileUpload::upcountName ( $name)
protected

Enter description here ...

Parameters
string$name???
Returns
string ???

Definition at line 421 of file fileupload.class.php.

Referenced by handleFileUpload(), and trimFileName().

◆ upcountNameCallback()

FileUpload::upcountNameCallback ( $matches)
protected

Enter description here ...

Parameters
int$matches???
Returns
string ???

Definition at line 408 of file fileupload.class.php.

◆ validate()

FileUpload::validate ( $uploaded_file,
$file,
$error,
$index )
protected

Make validation on an uploaded file.

Parameters
string$uploaded_fileUpload file
object$fileFile
string$errorError
string$indexIndex
Returns
boolean True if OK, False if KO

Definition at line 346 of file fileupload.class.php.

References dol_filesize(), and getFileObjects().

Referenced by handleFileUpload().


The documentation for this class was generated from the following file: