IUpload.js

Upload files without flash while simulating asynch using a dynamically created I-Frame and JSON callbacks

IUpload a cross browser single file uploader alternative to flash

Parameters

Default params, what the parameters will default to if not specified, if you specify a parameter as Null, the value in the iframe will not be overwritten with Javascript

[javascript]
{
  container:"#uploadContainer",
  iframe_src:"iupload/iframe.html",
  action:"upload.php",
  label:"Upload a File",
  file_name:"iuploadFile",
  extra_html:""
}

Build the Iframe

[javascript]
var element = document.getElementById("uploadContainer");
// example with all options, none are required, the defaluts above will be used if omitted
var uploader = new dpm.IUpload({container:'#uploadContainer', frame_src:'../../iupload/iframe.html', file_name:'iuploadFile',action:'../examples/php/upload.php', '<input type="hidden" name="extra" value="extra"/>'});

Handle the Response

[javascript]
// fired on upload start, passes in the name of the file being sent.
uploader.uploadStart = function(fileName){
  alert( 'uploading ' + fileName );
}

// fired when the upload is complete
uploader.uploadComplete = function(response){
  if( response.status == "success" ){
    $('#images').append( '<img src="' + response.file + '" />' );
  }else{
    alert(response.message);
  }
}

Server side usage

[html]
// error
<script type="text/javascript">
  window.response = {message: "could not move uploaded file", status: "error"}
</script>
// success
<script type="text/javascript">
  window.response = {file: "http://www.newfinds.com/someimage.jpg", status: "success"}
</script>

IUpload.js On GitHub

Logo