/
bbsupload.php
209 lines (200 loc) · 6.11 KB
/
bbsupload.php
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
<?php
require("www2-funcs.php");
require("www2-bmp.php");
$sessionid = login_init(TRUE);
assert_login();
if (isset($_POST['type']))
$type=$_POST['type'];
else if (isset($_GET['type']))
$type=$_GET['type'];
else
$type='';
if (strcasecmp($type, 'msg')==0)
$max_file_count=1;
else
$max_file_count=BBS_MAXATTACHMENTCOUNT;
@$action=$_GET["act"];
$msg = "";
if ($action=="delete") {
@$act_attachname=$_GET["attachname"];
settype($act_attachname, "string");
$filename = base64_decode($act_attachname);
$ret = bbs_upload_del_file($filename);
if ($ret) $msg = bbs_error_get_desc($ret);
else $msg = "删除 " . $filename . " 成功";
} else if ($action=="add") {
$counter = @intval($_POST["counter"]);
for($i = 0; $i < $counter; $i++) {
if (!isset($_FILES['attachfile' . $i])) {
continue;
}
$attpost = $_FILES['attachfile' . $i];
@$errno = $attpost['error'];
switch ($errno) {
case UPLOAD_ERR_OK:
$ofile = $attpost['tmp_name'];
if (!file_exists($ofile)) {
$msg .= "文件传输出错!";
break 2;
}
$oname = $attpost['name'];
$htmlname = htmlspecialchars(my_basename($oname));
if (!is_uploaded_file($ofile)) {
die;
}
if (compress_bmp($ofile, $oname)) {
$msg .= "过大 BMP 图片 " . $htmlname . " 被自动转换成 PNG 格式。<br/>";
}
$ret = bbs_upload_add_file($ofile, $oname);
if ($ret) $msg .= bbs_error_get_desc($ret);
else {
$msg .= $htmlname . "上传成功!<br/>";
continue 2;
}
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$msg .= "文件超过上限 " . sizestring(BBS_MAXATTACHMENTSIZE) . " 字节";
break;
case UPLOAD_ERR_PARTIAL:
$msg .= "文件传输出错!";
break;
case UPLOAD_ERR_NO_FILE:
continue 2;
$msg .= "没有文件上传!";
break;
default:
$msg .= "未知错误";
}
break;
}
}
$attachments = bbs_upload_read_fileinfo();
$filecount = count($attachments);
$allnames = array();$totalsize=0;
for($i=0;$i<$filecount;$i++) {
$allnames[] = $attachments[$i]["name"];
$totalsize += $attachments[$i]["size"];
}
$allnames=implode(",",$allnames);
page_header("上传附件", FALSE);
?>
<body>
<script type="text/javascript">
<!--
function checkAnyFiles() {
var frm = document.forms[0];
var i;
for (i=0; i<fileCounter; i++) {
var o = frm.elements["attachfile"+i];
if (o.value) return true;
}
return false;
}
function addsubmit() {
if (!checkAnyFiles()){
alert('您还没选择上传的附件');
return false;
} else {
var frm = document.forms[0];
var e2="bbsupload.php?act=add";
getObj("winclose").style.display = "none";
frm.counter.value = fileCounter;
frm.action=e2;
frm.paste.value='附件上传中,请稍候...';
frm.paste.disabled=true;
frm.submit();
return true;
}
}
function deletesubmit(f) {
var e2="bbsupload.php?act=delete&attachname="+f;
document.forms[1].action=e2;
document.forms[1].submit();
}
function clickclose() {
if (!checkAnyFiles()) return window.close();
else if (confirm("您填写了文件名,但没有上传。是否确认关闭?")==true) return window.close();
return false;
}
var fileCounter = 0, fileRemains = <?php echo ($max_file_count - $filecount); ?>;
function moreAttach() {
var ll = getObj("idAddAtt");
var n = document.createElement("br");
getObj("uploads").insertBefore(n, ll);
if (gIE && !gIE9) {
n = document.createElement("<input name='attachfile" + fileCounter + "'/>");
} else {
n = document.createElement("input");
n.setAttribute('name', 'attachfile' + fileCounter);
}
n.setAttribute('type', 'file');
n.setAttribute('size', 30);
getObj("uploads").insertBefore(n, ll);
fileCounter++;
if (fileCounter >= fileRemains) ll.style.display = "none";
}
function allAttach() {
while(fileCounter < fileRemains) moreAttach();
}
addBootFn(function() {
if (fileRemains > 0) {
getObj("idAddAtt").style.display = "inline";
getObj("idAllAtt").style.display = "inline";
moreAttach();
}
if (opener) {
try {
opener.document.forms["postform"].elements["attachname"].value = "<?php echo $allnames; ?>";
} catch(e) {}
} else {
getObj("winclose").style.display = "none";
}
});
//-->
</script>
<div style="width: 550px; margin: 1em auto;">
<?php if ($msg) echo "<font color='red'> 提示:".$msg."</font>"; ?>
<form name="addattach" method="post" ENCTYPE="multipart/form-data" class="left" action="">
<input type="hidden" name="type" value="<?php echo $type; ?>" />
<input type="hidden" name="counter" vaue="0" />
<?php if ($sessionid) echo "<input type='hidden' name='sid' value='$sessionid' />"; ?>
选择需要上传的文件后点上传:(<a id="idAllAtt" style="display:none;" href="javascript:void(0);" onclick="allAttach();">我要传好多附件</a>)
<div id="uploads">
<?php
if ($filecount<$max_file_count) {
?>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo(BBS_MAXATTACHMENTSIZE);?>" />
<a id="idAddAtt" style="margin-left: 1em; display:none;" href="javascript:void(0);" onclick="moreAttach();">增加一个附件</a>
<?php
} else {
?>
附件个数已满!
<input type="hidden" name="attachfile" />
<?php
}
?>
</div>
<input type="button" value="上传" name="paste" onclick="addsubmit();" />
<input type="button" id="winclose" value="上传完成, 关闭窗口" onclick="return clickclose()" />
<p>附件文件总量:<?php echo sizestring($totalsize); ?> 字节,
上限:<?php echo sizestring(BBS_MAXATTACHMENTSIZE); ?> 字节,
还能上传:<font color="#FF0000"><b><?php $rem = BBS_MAXATTACHMENTSIZE-$totalsize;
if ($rem < 0) $rem = 0; echo sizestring($rem); ?> 字节</b></font>.</p>
</form>
<form name="deleteattach" ENCTYPE="multipart/form-data" method="post" class="left" action="">
<input type="hidden" name="type" value="<?php echo $type; ?>" />
<?php if ($sessionid) echo "<input type='hidden' name='sid' value='$sessionid' />"; ?>
<ol style="padding-left: 2em; margin-left: 0em;">已经上传的附件列表: (最多能上传 <?php echo $max_file_count; ?>
个, 还能上传 <font color="#FF0000"><b><?php echo ($max_file_count-$filecount); ?></b></font> 个)
<?php
for($i=0;$i<$filecount;$i++) {
$f = $attachments[$i];
echo "<li>".$f["name"]." (".sizestring($f["size"])."字节) <a href=\"javascript:deletesubmit('".base64_encode($f["name"])."');\">删除</a></li>";
}
?>
</ol>
</form>
</div>
</body>
</html>