AJAX simple file upload

Upload multiple files with progress. Has hooks for pre/post work

How to use

include ajaxFileUploadSimeple.js

How to run

init with initAjaxUploader(ConfigObject)

Where the config object can have the following settings

Config Object settiings

{String} target_file

Must be set prefix for the element for the file upload

{String} target_form

Must be set the master form in which this element sits

{Number} [max_files=1]

maximum uploadable files, if 1, multiple will be removed from input file field, if 0, no limit

{Number} [max_file_size=0]

In bytes, maximum file size. If not set unlimited. 0 is also unlimited

{Array} [allowed_extensions=[]]

Allowed file extensions. Without leading '.'. Will be added to the input file accept list

{Array} [allowed_file_types=[]]

Allowed file types in mime format. Will be added to the input file accept list

{String} [target_router='']

value of the action _POST variable, if not set or if empty use "fileUpload"

{String} [target_action='']

override the target_form action field

{Object} [form_parameters={}]

Key/Value list for additional parameters to add to the form submit. Added BEFORE fileBeforeUpload parameters

{Object} [translation={}]

Translated strings pushed into the AFUS_strings object

{Boolean} [auto_submit=false]

if we override the submit button and directly upload

{Function} [fileChange='']

Function run on change of -file element entry. Parameters are target_file, file_pos, target_router

{Function} [fileChangeAll='']

Function run on change of -file element entry after all file changes for each entry are run. Parameters are target_file, target_router

{Function} [fileRemove='']

Called when an upload file is removed from the queue before upload. Parameters are target_file, file_pos

{Functuon} [fileClear='']

called when clear button is pressed. Parameters are target_file

{Function} [fileBeforeUploadAll='']

Function called before uploads start. Parameters are target_file, target_router

{Function} [fileBeforeUpload='']

Function called before upload starts. Parameters are target_file, file_pos, target_router

{Function} [fileUploaded='']

Function called after upload has successfully finished. Parameters are target_file, file_pos, target_router, data (object returned from upload function call)

{Function} [fileUploadedAll='']

After all uploads have been done, this one will be called. Parameters are target_file, target_router

{Function} [fileUploadError='']

Function called after upload has failed. Parameters are target_file, file_pos, target_router, data (object returned from upload function call)

Method call flow

[**1**] initAjaxUploader
[1 run 2] check if browser is capable for uploader
[1 run 1-A] run config check
[1 listen 8-C] cancel upload output
[1 run 3] afusPassThroughEvent
[1 run 4] run main file uploader function attachment
[1-A] afusUploaderConfigCheck check and clean config
[**2**] afusSupportAjaxUploadWithProgress
[**3**] afusPassThroughEvent
[3 set 1] change event on input file
[3 call 3-A] file extension check
[3 call 3-B] file type check
[3 set 2] sets upload queue delete in fileChange function
[3 ext 2-1] fileRemove function
[3 ext] fileChange function
[3 ext] fileChangeAll
[3 set 3] call click submit if auto submit
[3-A] afusHasExtension
[3-B] afusHasFileType
[**4**] afusInitFullFormAjaxUpload
[4 set 1] on submit function
[4 ext] fileBeforeUploadAll function
[4 run 6] afusSendFile main file send (promise)
[4 run 5] call class for async submitter iterator
[4 on finally call 8-C] finally promise: afusFinalPostUpload
[4 on finally ext] finally promise: call fileUploadedAll external
[**5**] class afusAsyncUploader
[5-A] class constructor for init
[5-B] iterator internal loop method for processing files
[**6**] afusSendFile
[6 ext] fileBeforeUpload function
[6] main xhr uploader start
[6 set 7-A] loadstart event afusOnloadStartHandler
[6 set 7-C] progress event afusOnProgressHandler
[6 set 7-B] load event afusOnloadHandler
[6 set 7-D] readystatechange event afusOnReadyStateChangeHandler
[7-A] afusOnloadStartHandler
[7-A call 9-A] add +1 to running
[7-B] afusOnloadHandler
[7-C] afusOnProgressHandler
[7-D] afusOnReadyStateChangeHandler
[7-D call 9-B] -1 for running queue count
[7-D call 8-B] afusUploadError
[7-D call 8-A] if success afusPostUpload
[7-D ext] if error fileUploadError function
[8-A] afusPostUpload
[8-B] afusUploadError
[8-C] afusCancelUploadOutput
[8-D] afusFinalPostUpload
[8-E] afusResetInternalVariables
[9-A] afusRunningStart
[9-B] afusRunningStop
[9-C] afusRunningGet
Description
Multiple file upload in sequence with javascript. Includes progress and pre/post hooks
Readme 404 KiB
Languages
JavaScript 86.6%
PHP 6.5%
HTML 5%
CSS 1.9%