Skip to content

Instantly share code, notes, and snippets.

@ss22219
Created November 4, 2013 16:10
Show Gist options
  • Save ss22219/7304908 to your computer and use it in GitHub Desktop.
Save ss22219/7304908 to your computer and use it in GitHub Desktop.
var uploader = new plupload.Uploader({
runtimes: 'gears,flash,html5,silverlight,browserplus',
browse_button: 'A3', container: 'content',
max_file_size: '10mb',
resize: { width: 320, height: 240, quality: 90 },
url: 'invoice.aspx',
flash_swf_url: 'js/Moxie.swf',
silverlight_xap_url: 'js/Moxie.xap',
filters: [
{ title: "图片", extensions: "jpg,gif,png" },
{ title: "zip压缩包", extensions: "zip" }
],
});
uploader.bind('Init', function (up, params) {
});
uploader.bind('QueueChanged', function () {
uploader.start();
})
uploader.bind('UploadProgress', function (up, file) {
if ($('#' + file.id).length == 0) {
$('#container').append('<p style="text-align:center">' + file.name + '</p><div class="progress progress-striped active"><div class="bar" id="' + file.id + '" style="width: ' + file.percent + '%;"></div></div>');
} else {
$('#' + file.id).css('width', file.percent + '%');
}
});
uploader.bind('Error', function (up, err) {
if (err.code == -601) {
alert('不支持该格式文件哦。');
} else if(err.code == -600){
alert("文件最大只能是3M哦。")
}
up.refresh(); // Reposition Flash/Silverlight
});
uploader.bind('FileUploaded', function (up, file, response) {
$('#' + file.id).parent().after('<img src="'+response.response+'" />');
$('#' + file.id).css('width', "100%");
});
uploader.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment