File Uploader
A file upload control that supports uploading multiple files, uploading inline (without reloading the page), and displaying upload progress on supported browser (Chrome, FF, Safari).
Demo
Source Example
<html>
<head>
<script language="javascript" src="protoplasm.js"></script>
<script language="javascript">
Protoplasm.use('upload').transform('input.upload', {
'inline': true,
'multiple': true
});
</script>
</head>
<body>
<form action="upload.php" method="post">
<input type="file" name="file" class="upload" />
</form>
</body>
</html>
Usage
To create upload controls out of all elements that match a given CSS rule:
Protoplasm.use('upload').transform(selector[, options]);
Parameters:
| Parameter | Required | Description | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| selector | yes | A CSS rule matching the text inputs to turn into color pickers | ||||||||||||||
| options | no |
An object (hash) containing name/value pairs of additional options.
Available options:
|
Upload Handling
Displaying upload progress in inline mode requires passing the data to the server in a different format than usual. Rather than encoding the file data as multipart/form-data, the upload control sets a "Content-Disposition" header, and passes the file data as the POST body. Since not all browsers support this, if you want to display file upload progress on supported browsers (the default in "inline" mode), you will need to support both upload methods in your server's upload handler.
In your upload handler, simply check for a "Content-Disposition" header. If it exists, the POST body contains the file data, and the file name can be retrieved from the header. If it does not exist, the file was uploaded in "multipart/form-data" encoding and can be processed like any other file upload.
To avoid this complication, you can also simply set the progress option to false, and files will always be submitted using multipart/form-data encoding.
Advanced Usage
If you want more control over creation and destruction of the upload control, you can instantiate it manually instead of using Protoplasm.transform.
In your <head> section:
Protoplasm.use('upload');
To create an upload control:
var upload = new Control.FileUpload(element[, options]);
To destroy the upload control:
upload.destroy();
For more details, see the API documentation for Control.FileUpload.