This plugin allows uploading files using the SWFUpload JavaScript/Flash library. You can easily convert your existing input fields into 'swf upload fields'.
SWFUpload offers many configuration settings to limit all kind of file parameters (size,type,number,..) and leaves the UI to the browser.
Just copy the "swfupload" folder into your xajax install below /xajax/xajax_plugins/request/.
If you have downloaded the full package just replace your old xajax install with the provided xajax folder. Do not copy the new folder into the old one!
include the plugin right after the xajax object instantiation and before configuring xajax.
$xajax = new xajax();
require_once './xajax/xajax_plugins/request/swfupload/swfupload.inc.php';
$xajax->configure("javascript URI","/swfupload/xajax/");
You can turn any xajax enabled function into an upload function by setting the mode to 'SWFupload':
$xajax->register(
XAJAX_FUNCTION,
"my_upload_function",
array("mode" => "'SWFupload'", "SWFfield" => 'my_field_id',"SWFform" => 'my_form_id')
);
The "mode" is required to enable file uploading via SWF. Both other parameters are optional.
When setting for instance "SWFfield" => 'field_id' it will only upload the file queue of the given field.
The same applies for "SWFform" => 'my_form_id', with the exception that it will upload all queues from all file inputs inside the given form.
You can only set either SWFform or SWFfield. Without setting one of these values the function will upload all files from all queues!
To trigger the upload you only have to call the generated xajax function stub (xajax_ + function name). You can even pass additional values:
<input type="submit" value="upload" onclick"xajax_my_upload_function(xajax.getFormValues('my_form'),'foo','bar');" >
The plugin provides two helper functions that will turn any file input fields into 'flash upload fields'.
This function parses the given form and replaces all file input fields inside the form.
xajax.ext.SWFupload.tools.transForm('upload_form',{
file_types : "*.jpg;*.gif",
file_types_description: "Web Image Files",
file_size_limit : "3 MB"
},
true
);
This function replaces the given input field.
xajax.ext.SWFupload.tools.transField('upload_field_id',{
file_types : "*.jpg;*.gif",
file_types_description: "Web Image Files",
file_size_limit : "3 MB"
},
false
);
Both functions support passing an optional config object and the 'multiple' option.
Setting the multiple option to true enables selecting multiple files at once
The full reference for all configuration parameters can be found here: SWFUpload docs
This function destroys the given input field and its associated objects.
xajax.ext.SWFupload.tools.destroyField(field_id);
This function destroys the all fields and its associated objects of the given form.
xajax.ext.SWFupload.tools.destroyForm(form_id);
All JavaScript functions are also available via xajax response commands.
$objResponse->clsSwfUpload->transForm('upload_form'
,array(
"file_types" => "*.jpg;*.gif;*.png;"
,"file_types_description" => "Image Files or mp3"
,"file_size_limit" => "5 MB"
,"upload_complete_handler" => "function () {
}"
,"post_params" => array(
"PHPSESSID" => session_id()
)
)
, true
);