<%@ Page Language="VB" %>
<script runat="server">
Sub Button1_Click(sender As Object, e As EventArgs)
if trim(upload_file.value)<>"" and trim(saveas_name.value)<>"" then
if check_filename(saveas_name.value) then '出错行,出错提示:表达式不产生值。
upload_file.postedfile.saveas(saveas_name.value)
response.write("上传文件成功"
saveas_name.value=""
else
response.write("error!"
end if
else
response.write("<script language=""javascript"">" & vbcrlf)
response.write("history.back(1)" & vbcrlf)
response.write("alert(""error!""
" & vbcrlf)
response.write("</" & "script" & ">" )
end if
End Sub
sub check_filename(byval check_filename as string) as boolean
if right(check_filename,3)<>"jpg" or right(check_filename,3)<>"png" or right(check_filename,3)<>"gif" then
return false
else
return true
end if
end sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<table height="150" cellpadding="4" width="300" align="center" bgcolor="#cccccc">
<tbody>
<tr>
<td bgcolor="#eeeeee">
选择上传文件:
<input id="upload_file" type="file" runat="server" />
<br />
另存为文件名:
<input id="saveas_name" type="text" runat="server" />
<br />
<br />
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="上传文件"></asp:Button>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>