Core API - Bundled example
author(s): Davit Barbakadze
by Andy BigBoy
HTML
<script src="http://rawgithub.com/moxiecode/plupload/master/js/plupload.full.min.js"></script>
<h1>Fiddle My Scout</h1>
<p>The most ephishent way to become a scout..</p>
<div id="filelist">.</div>
<br />
<div id="container">
<a id="pickfiles" href="javascript:;">[becoming a sprout]</a>
<a id="uploadfiles" href="javascript:;">[not becoming a sprout]</a>
</div>
<br />
<pre id="console"></pre>
JavaScript
// jQuery not really required, it's here to overcome an inability to pass configuration options to the fiddle remotely
$(document).ready(function() {
// Custom example logic
function $(id) {
return document.getElementById(id);
}
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: $('container'), // ... or DOM Element itself
max_file_size : '10mb',
// Fake server response here
// url : '../upload.php',
url: "/echo/json",
flash_swf_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/flash/Moxie.cdn.swf',
silverlight_xap_url : 'http://rawgithub.com/moxiecode/moxie/master/bin/silverlight/Moxie.cdn.xap',
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
init: {
PostInit: function() {
$('filelist').innerHTML = '';
$('uploadfiles').onclick = function() {
uploader.start();
return false;
};
},
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
$('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
});
},
UploadProgress: function(up, file) {
$(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
Error: function(up, err) {
$('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
}
});
uploader.init();
});