-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
111 lines (97 loc) · 2.89 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title></title>
<link href="http://libs.useso.com/js/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link href="http://libs.useso.com/js/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<div class="container">
<h2>Demo</h2>
<ul>
<li>使用方法请看源代码及注释</li>
</ul>
<a href="#" id="uploadBtn" class="btn">Upload</a>
</div>
<script src="plupload/plupload.full.min.js"></script>
<script src="plupload/myPlupload.js"></script>
<script>
/*
基于 www.plupload.com/docs/
与官方API 完全兼容 的基础上增加:
autoUpload: 选择文件后自动上传 默认为false
multipart_params: 可传object json 或者 返回json 的 function(){} 若为function 每次上传都为运行以拿到最新数据(常用于表单)
Error: 发生错误都会console.log 错误信息
如果设定 autoUpload: false 的话
可以通过 uploader.start() 启动上传
初次使用时注意 确认 plupload/haierUpload.js 里面的
flash_swf_url
silverlight_xap_url
配置url正确
FAQ:
跨域上传配置文件 plupload/crossdomain.xml 放在域名的根目录下 如: abc.com/crossdomain.xml
*/
var uploader = myPlupload({
url: 'http://admin.main.test.hotoem.com/Common/UploadImage?dir=image',
// http://admin.main.test.hotoem.com/Common/UploadImage?dir=image
browse_button: 'uploadBtn', // 触发选择文件的 DOM 元素 ID
autoUpload: true, // 可选 默认为false
file_data_name: 'file', // 可选 默认为 当前值
multi_selection: false, // 可选 默认为 true
multipart_params: function(){ // 可选
return {
username: 'abc'
}
},
filters : { // 可选 默认为当前配置
max_file_size : '500kb',
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
prevent_duplicates: false // default
},
init: {
FileUploaded: function(up, files, response, json){
// 上传成功后执行
console.log(response);
console.log(json);
},
PostInit: function(up, file){ // 可选
// 初始化执行
// alert("初始化");
},
BeforeUpload: function(up, file){ // 可选
// 上传之前执行
// alert('上传之前');
},
FilesAdded: function(up, file){ // 可选
// 添加文件执行
},
UploadProgress: function(up, file){ // 可选
console.log(file.percent);
},
Error: function(up, err){ // 可选
console.log(err);
alert('error');
}
}
});
// 最小配置
var uploader = myPlupload({
url: 'http://admin.main.test.hotoem.com/Common/UploadImage?dir=image',
browse_button: 'uploadBtn2',
autoUpload: true, // 可选 默认为false
init: {
FileUploaded: function(up, files, response, json){
// 上传成功后执行
console.log(response);
console.log(json);
}
}
});
</script>
</body>
</html>