Skip to content

Instantly share code, notes, and snippets.

@repoplus
Last active August 19, 2016 05:42
Show Gist options
  • Save repoplus/672879a06c2beba6cdd59ec6deb9e15b to your computer and use it in GitHub Desktop.
Save repoplus/672879a06c2beba6cdd59ec6deb9e15b to your computer and use it in GitHub Desktop.
plupload 上传插件

plupload 上传插件配置

所需支持
<script type="text/Javascript" src="<%=contextPath%>/plupload/jquery-1.7.2.min.js"></script>
<link rel="stylesheet" href="<%=contextPath%>/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css"/>
<script type="text/javascript" src="<%=contextPath%>/plupload/plupload.full.min.js"></script>
<script type="text/javascript" src="<%=contextPath%>/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="<%=contextPath%>/plupload/i18n/zh_CN.js"></script>
页面代码
<body>
	
	<div id="uploader" style="width: 500px;height: 500px;border: 1px solid;"></div>

<script type="text/javascript">
	
	var hasError = false;
	$(document).ready(function() {  
		$("#uploader").pluploadQueue({
	        runtimes 			: 'html5,gears,browserplus,silverlight,flash,html4',
	        url 				: "Upload",
	        max_file_size 		: "100MB",
	        multiple_queues 	: false,
	        unique_names		: true,
	        rename				: true,
	        dragdrop            : true, 
	        urlstream_upload	: true,
	        multi_selection     : false,
	        filters 			: [	{title : "Excel files", extensions : "xls"}],
	        flash_swf_url		: "<%=contextPath%>/plupload/Moxie.swf",
	        silverlight_xap_url : "<%=contextPath%>/plupload/Moxie.xap",
	        init			    : {
				FilesAdded:function(up,files){ //控制只能添加一个文件
					$.each(up.files, function (i, file) {
				        if (up.files.length <= 1) {
				            return;
				        }
			       		up.removeFile(file);
		    		});
		    	},
		    	UploadComplete:function(up,files){ //上传完成
			    	if(!hasError){
			    		
			    		alert('处理成功')
			    		
			    	}else {
			    		
			    		alert('文件上传获取解析失败')
			    		
			    		hasError = false;
			    	}
		    	},
		    	Error: function(up, args) { //上传失败
			    	hasError = true;
		    	}
	        }
	    });
	});
		
</script>

</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment