<!DOCTYPE html>
<html>
<head>
<title>上传附件demo</title>
</head>
<body>
<button type="button" id="uploadpic" onclick="uploadpic('uploadpic',"")"></button>
</body>
<script type="text/javascript">
//图片上传
var isloginvshow=false;
function uploadpic(browserbtn, importurl, callback) {
if(importurl == null){
importurl = "";
}
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
multi_selection : false,
unique_names : true,
browse_button : browserbtn, // you can pass in id...
file_data_name:'file',
url : rootURL,
filters : {
max_file_size : '10mb',
mime_types : [ {
title : "素材文件",
extensions : "jpg,png"
} ]
},
// Flash settings
flash_swf_url : rootURL + '/assets/javascripts/Moxie.swf',
// Silverlight settings
silverlight_xap_url : rootURL + '/assets/javascripts/Moxie.xap',
init : {
PostInit : function() {
},
Init:function(){
if(navigator.userAgent.indexOf("MSIE 8.0")>0) {
$("div.moxie-shim").eq(0).height(31);
$("div.moxie-shim").eq(0).width(78);
$("div.moxie-shim").eq(0).position().left=11;
}
},
FilesAdded : function(up, files) {
// start upload after the file is selected
uploader.settings.url = rootURL
+ importurl;
uploader.start();
},
UploadProgress : function(up, file) {
// $("#upload-progress").removeClass("hide");
},
FileUploaded : function(up, file, res) {
$("#upload-progress").hide();
if (callback) {
var response = res.response;
if(response){
response = response.replace("<PRE>","").replace("</PRE>","");
}
callback(JSON.parse(response), file);
}
},
Error : function(up, err) {
alert("上传失败");
// $("#upload-progress").addClass("hide");
MessageBox.error(err.message);
}
}
});
uploader.init();
}
</script>
</html>