upload2.html
7.65 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Uploadify</title>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/uploadify/uploadify.css" />
</head>
<body>
<div class="W">
<div class="Bg"></div>
<div class="Wrap" id="Wrap">
<div class="Title">
<h3 class="MainTit" id="MainTit">{$info.title}</h3>
<a href="javascript:Close();" title="关闭" class="Close"></a>
</div>
<div class="Cont">
<p class="Note">最多上传<strong id="picnum">{$info.num}</strong>个附件,单文件最大<strong>{$info.size}</strong>,类型<strong>{$info.type}</strong></p>
<div class="flashWrap">
<input name="uploadify" id="uploadify" type="file" multiple="true" />
<!-- <span><input type="checkbox" name="iswatermark" id="iswatermark" /><label>是否添加水印</label></span>-->
</div>
<div class="fileWarp">
<fieldset>
<legend>列表</legend>
<ul>
</ul>
<div id="fileQueue">
</div>
</fieldset>
</div>
<div class="btnBox">
<button class="btn" id="SaveBtn">保存</button>
<button class="btn" id="CancelBtn">取消</button>
</div>
</div>
<!--[if IE 6]>
<iframe frameborder="0" style="width:100%;height:100px;background-color:transparent;position:absolute;top:0;left:0;z-index:-1;"></iframe>
<![endif]-->
</div>
</div>
<input type="hidden" id="isdellocalimg" name="isdellocalimg" value="{$info.isdellocalimg}">
<input type="hidden" id="hidtablename" name="hidtablename" value="{$info.tablename}">
<script src="__PUBLIC__/plugins/uploadify/jquery.min.js" type="text/javascript"></script>
<!--防止客户端缓存文件,造成uploadify.js不更新,而引起的“喔唷,崩溃啦”-->
<script>document.write("<script type='text/javascript' "+ "src='__PUBLIC__/plugins/uploadify/jquery.uploadify.js?" + new Date()+ "'></s" + "cript>");
</script>
<script src="__PUBLIC__/plugins/uploadify/uploadify-move.js" type="text/javascript"></script>
<script type="text/javascript">
function Close(){
$("iframe.uploadframe", window.parent.document).remove();
}
$("#CancelBtn").click(function(){
$("iframe.uploadframe", window.parent.document).remove();
//$('#uploadify').uploadifyClearQueue();
//$(".fileWarp ul li").remove();
});
$(function() {
$('#uploadify').uploadify({
'auto' : true,
'method' : 'post',
'multi' : true,
'swf' : '__PUBLIC__/plugins/uploadify/uploadify.swf',
'uploader' : "{$info.upload}",
'progressData' : 'all',
'queueSizeLimit' : {$info.num},
'uploadLimit' : {$info.num},
'fileSizeLimit' : '500KB',
'fileTypeDesc' : '',
'fileTypeExts' : '',
'buttonImage' : '/public/plugins/uploadify/select.png',
'queueID' : 'fileQueue',
'onUploadStart' : function(file){
$('#uploadify').uploadify('settings', 'formData', {'iswatermark':$("#iswatermark").is(':checked')});
},
//检测FLASH失败调用
'onFallback': function () {
alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
},
'onUploadSuccess' : function(file, data, response){
$(".fileWarp ul").append(SetImgContent(data));
SetUploadFile();
}
});
});
function SetImgContent(data){
var obj=eval('('+data+')');
if(obj.state == 'SUCCESS'){
var sLi = "";
sLi += '<li class="img">';
sLi += '<img src="' + obj.url + '" width="100" height="100" onerror="this.src=\'__WEBPUBLIC__/plugins/uploadify/nopic.png\'">';
sLi += '<input type="hidden" name="fileurl_tmp[]" value="' + obj.url + '">';
sLi += '<a href="javascript:void(0);">删除</a>';
sLi += '</li>';
return sLi;
}else{
//window.parent.message(obj.text,8,2);
alert(obj.text);
return;
}
}
function SetUploadFile(){
$("ul li").each(function(l_i){
$(this).attr("id", "li_" + l_i);
})
$("ul li a").each(function(a_i){
$(this).attr("rel", "li_" + a_i);
}).click(function(){
$.get(
'{:U("Admin/Uploadify/delupload")}',{action:"del",delqclo:"1", filename:$(this).prev().val()},function(){}
);
if ($("#picnum").text()=="1")
{
location.href=location.href;
}
else {
$("#" + this.rel).remove();
}
})
}
/*点击保存按钮时
*判断允许上传数,检测是单一文件上传还是组文件上传
*如果是单一文件,上传结束后将地址存入$input元素
*如果是组文件上传,则创建input样式,添加到$input后面
*隐藏父框架,清空列队,移除已上传文件样式*/
$("#SaveBtn").click(function(){
var callback = "{$info.func}";
var num = {$info.num};
var fileurl_tmp = [];
var isdelsm="0";
if ($("#hidtablename").val()=="goods" || $("#hidtablename").val()=="goods_images")
{
isdelsm="1";
}
if(callback != "undefined"){
if(num > 1){
$("input[name^='fileurl_tmp']").each(function(index,dom){
fileurl_tmp[index] = dom.value;
//是否删除本地
if ($("#isdellocalimg").val()=="1") {
$.ajax({
type:'GET',
url:"{:U('Admin/Uploadify/delupload')}",
data:{tablename:""+$("#hidtablename").val()+"",action: "del", filename:dom.value,delsmall:isdelsm},
success:function(){
//
},
error:function () {
}
});
} else
{
}
});
eval('window.parent.'+callback+'(fileurl_tmp)');
$(window.parent.document).find("iframe.uploadframe").remove();
}else{
fileurl_tmp = $("input[name^='fileurl_tmp']").val();
//是否删除本地
if ($("#isdellocalimg").val()=="1") {
$.ajax({
type:'GET',
url:"{:U('Admin/Uploadify/delupload')}",
dataType:'json',
data:{tablename:""+$("#hidtablename").val()+"",action: "del", filename:fileurl_tmp,delsmall:isdelsm},
success:function(data){ //
if ($("#hidtablename").val()=="store_wximglist")
{
fileurl_tmp+="|"+data.media_id;
eval('window.parent.'+callback+'(fileurl_tmp)');
}
else
{
eval('window.parent.'+callback+'(fileurl_tmp)');
}
$(window.parent.document).find("iframe.uploadframe").remove();
},
error:function () {
$(window.parent.document).find("iframe.uploadframe").remove();
}
});
}
else
{
eval('window.parent.'+callback+'(fileurl_tmp)');
$(window.parent.document).find("iframe.uploadframe").remove();
}
}
return;
}
if(num > 1){
var fileurl_tmp = "";
$("input[name^='fileurl_tmp']").each(function(){
fileurl_tmp += '<li rel="'+ this.value +'"><input class="input-text" type="text" name="{$info.input}[]" value="'+ this.value +'" /><a href="javascript:void(0);" onclick="ClearPicArr(\''+ this.value +'\',\'\')">删除</a></li>';
});
$(window.parent.document).find("#{$info.input}").append(fileurl_tmp);
}else{
$(window.parent.document).find("#{$info.input}").val($("input[name^='fileurl_tmp']").val());
}
$(window.parent.document).find("iframe.uploadframe").remove();
});
</script>
</body>
</html>