Ajax
in package
Tags
Table of Contents
Constants
- json_data_identifier = '_AJAX_json_decode_data'
- json_list_identifier = '_AJAX_json_decode_list'
Properties
- $max_file_uploads : int
- default max number of file to upload in a single request this value can be overridden by the configuration file
- $max_upload_size : int
- default max upload size in bytes (1.6 GB) this value can be overridden by the configuration file
- $stockage_left : int
- current storage left in bytes this value is updated by the file_upload_max_size() function and can be used to display the storage left in the UI
- $stockage_percentage : int
- current storage usage percentage this value is updated by the file_upload_max_size() function and can be used to display the storage usage in the UI
- $stockage_quota : int
- default storage quota in bytes (5 GB) this value is generaly overridden by the configuration file main.php in the "config" instance folder
- $stockage_usage : int
- current storage usage in bytes this value is updated by the file_upload_max_size() function
Methods
- __construct() : mixed
- check_file_extension() : mixed
- check_filename() : mixed
- export_json_data() : string
- This function exports data as a JSON response.
- file_upload_max_count() : mixed
- file_upload_max_size() : int
- it will calculate the state of the storage and the maximum file upload size possible.
- get_server_variables_as_js() : string
- This function retrieves server variables related to storage and file upload limits, and formats them as JavaScript variables for use in the client-side code.
- merge_chunks() : string
- As the name suggests, this function merges the chunks of a file that were uploaded in parts.
- move_from_temp() : array<string|int, mixed>|bool
- Move the files from the temporary folder to the specified relative path.
- origin_security_test() : bool
- This function checks the HTTP_ORIGIN header against a list of accepted origins.
- process_all_data() : mixed
- process_data() : array<string|int, mixed>
- This function processes the input data by decoding JSON strings that are identified by the Ajax::json_list_identifier key
- process_files() : array<string|int, mixed>
- Put the received files in the given destination folder This function processes file uploads from the $_FILES superglobal.
- process_tinymce_upload() : json
- Description for process_tinymce_upload
- update_storage_status() : void
- This function updates the storage status by writing the current server variables related to storage and file upload limits into a JavaScript file (storages.js) for instance js side.
Constants
json_data_identifier
public
mixed
json_data_identifier
= '_AJAX_json_decode_data'
json_list_identifier
public
mixed
json_list_identifier
= '_AJAX_json_decode_list'
Properties
$max_file_uploads
default max number of file to upload in a single request this value can be overridden by the configuration file
public
static int
$max_file_uploads
= 20
Tags
$max_upload_size
default max upload size in bytes (1.6 GB) this value can be overridden by the configuration file
public
static int
$max_upload_size
= 1677721600
Tags
$stockage_left
current storage left in bytes this value is updated by the file_upload_max_size() function and can be used to display the storage left in the UI
public
static int
$stockage_left
= 5368709120
Tags
$stockage_percentage
current storage usage percentage this value is updated by the file_upload_max_size() function and can be used to display the storage usage in the UI
public
static int
$stockage_percentage
= 0
Tags
$stockage_quota
default storage quota in bytes (5 GB) this value is generaly overridden by the configuration file main.php in the "config" instance folder
public
static int
$stockage_quota
= \Config::STORAGE_COTA
$stockage_usage
current storage usage in bytes this value is updated by the file_upload_max_size() function
public
static int
$stockage_usage
= 0
Tags
Methods
__construct()
public
__construct() : mixed
check_file_extension()
public
static check_file_extension(mixed $name, mixed $extensions) : mixed
Parameters
- $name : mixed
- $extensions : mixed
check_filename()
public
static check_filename(mixed $name) : mixed
Parameters
- $name : mixed
export_json_data()
This function exports data as a JSON response.
public
static export_json_data(mixed $data) : string
Parameters
- $data : mixed
Return values
string —JSON encoded string
file_upload_max_count()
public
static file_upload_max_count() : mixed
file_upload_max_size()
it will calculate the state of the storage and the maximum file upload size possible.
public
static file_upload_max_size() : int
This function checks the PHP configuration settings for post_max_size and upload_max_filesize, For js and php process.
Return values
int —the maximum file upload size in bytes
get_server_variables_as_js()
This function retrieves server variables related to storage and file upload limits, and formats them as JavaScript variables for use in the client-side code.
public
static get_server_variables_as_js() : string
Those variables can be used to display storage information in the UI or to handle file uploads. and to allow upload depending on the storage left
Return values
string —containing the server variables as JavaScript variables
merge_chunks()
As the name suggests, this function merges the chunks of a file that were uploaded in parts.
public
static merge_chunks([string $name = '' ][, int $chunk_number = 0 ][, string $unique_id = '' ][, bool $update_storage = true ]) : string
It takes the name of the file, the total number of chunks, a unique identifier and a boolean to indicate whether to update the storage status.
Parameters
- $name : string = ''
- $chunk_number : int = 0
- $unique_id : string = ''
- $update_storage : bool = true
Return values
string —a json encoded string with the missing slices if any, or 'ok' if all chunks were successfully merged.
move_from_temp()
Move the files from the temporary folder to the specified relative path.
public
static move_from_temp([bool $relativePath = false ][, bool $fileLst = [] ][, null $extensions = null ]) : array<string|int, mixed>|bool
Parameters
- $relativePath : bool = false
- $fileLst : bool = []
- $extensions : null = null
Return values
array<string|int, mixed>|boolorigin_security_test()
This function checks the HTTP_ORIGIN header against a list of accepted origins.
public
static origin_security_test() : bool
do not forget to set the BASE_URL in the configuration file main.php
Return values
bool —true if the origin is accepted, false if not
process_all_data()
public
static process_all_data() : mixed
process_data()
This function processes the input data by decoding JSON strings that are identified by the Ajax::json_list_identifier key
public
static process_data([null $data = null ]) : array<string|int, mixed>
Parameters
- $data : null = null
Return values
array<string|int, mixed> —processed data
process_files()
Put the received files in the given destination folder This function processes file uploads from the $_FILES superglobal.
public
static process_files([mixed $destinationDir = null ][, null $extensions = null ][, null $chunk = null ]) : array<string|int, mixed>
It handles both single and multiple file uploads, checks for valid file names and extensions and the rights to upload to the destination directory.
Parameters
- $destinationDir : mixed = null
-
=null (must be specified, otherwise the default uploads directory will be used)
- $extensions : null = null
-
array with all authorized files extensions
- $chunk : null = null
Return values
array<string|int, mixed> —containing all files paths and size associated to original variables names exemple: array( VARNAME_A => array( array('path' => 'images/photo1' , size => 14543) , array('path' => 'images/photo2' , size => 637684) ) , VARNAME_B => array( array('path' => 'images/photo3' , size => 987457) ) );
process_tinymce_upload()
Description for process_tinymce_upload
public
static process_tinymce_upload([null $destinationDir = null ]) : json
Parameters
- $destinationDir : null = null
Tags
Return values
json —JSON encoded string with the location of the uploaded file This function processes file uploads specifically for TinyMCE editor. It handles only image uploads (gif, jpg, png, jpeg, svg).
update_storage_status()
This function updates the storage status by writing the current server variables related to storage and file upload limits into a JavaScript file (storages.js) for instance js side.
public
static update_storage_status() : void