XAJAX SWFupload Plugin

demo

The file size is limited to 5MB. Don't even think about hijacking the form, all your uploads will safely be stored in /dev/null. :)
test field:
Normal field 1:
Normal field 2:
 
 

response

XAJAX SWFupload Plugin 0.2


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.

changelog

2008-04-11 vers 0.2.1
2008-04-10 vers 0.2
2008-04-07 vers 0.1

supported configurations

install

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!

usage

configuration

function registration

JavaScript functions

response functions

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/");

function registration

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');" >

Javascript functions

The plugin provides two helper functions that will turn any file input fields into 'flash upload fields'.

xajax.ext.SWFupload.tools.transForm

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
 	);

xajax.ext.SWFupload.tools.transField

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


xajax.ext.SWFupload.tools.destroyField

This function destroys the given input field and its associated objects.

xajax.ext.SWFupload.tools.destroyField(field_id);

xajax.ext.SWFupload.tools.destroyForm

This function destroys the all fields and its associated objects of the given form.

xajax.ext.SWFupload.tools.destroyForm(form_id);

response functions

All JavaScript functions are also available via xajax response commands.