[ASP]精华代码
程序员文章站
2022-06-21 22:57:25
复制代码 代码如下:<% ' -- loader.asp -- ' --&nb...
复制代码 代码如下:
<%
' -- loader.asp --
' -- version 1.5.2
' -- last updated 12/5/2002
'
' faisal khan
' faisal@stardeveloper.com
' www.stardeveloper.com
' class for handling binary uploads
class loader
private dict
private sub class_initialize
set dict = server.createobject("scripting.dictionary")
end sub
private sub class_terminate
if isobject(intdict) then
intdict.removeall
set intdict = nothing
end if
if isobject(dict) then
dict.removeall
set dict = nothing
end if
end sub
public property get count
count = dict.count
end property
public sub initialize
if request.totalbytes > 0 then
dim bindata
bindata = request.binaryread(request.totalbytes)
getdata bindata
end if
end sub
public function getfiledata(name)
if dict.exists(name) then
getfiledata = dict(name).item("value")
else
getfiledata = ""
end if
end function
public function getvalue(name)
dim gv
if dict.exists(name) then
gv = cstr(dict(name).item("value"))
gv = left(gv,len(gv)-2)
getvalue = gv
else
getvalue = ""
end if
end function
public function savetofile(name, path)
if dict.exists(name) then
dim temp
temp = dict(name).item("value")
dim fso
set fso = server.createobject("scripting.filesystemobject")
dim file
set file = fso.createtextfile(path)
for tpoint = 1 to lenb(temp)
file.write chr(ascb(midb(temp,tpoint,1)))
next
file.close
savetofile = true
else
savetofile = false
end if
end function
public function getfilename(name)
if dict.exists(name) then
dim temp, temppos
temp = dict(name).item("filename")
temppos = 1 + instrrev(temp, "\")
getfilename = mid(temp, temppos)
else
getfilename = ""
end if
end function
public function getfilepath(name)
if dict.exists(name) then
dim temp, temppos
temp = dict(name).item("filename")
temppos = instrrev(temp, "\")
getfilepath = mid(temp, 1, temppos)
else
getfilepath = ""
end if
end function
public function getfilepathcomplete(name)
if dict.exists(name) then
getfilepathcomplete = dict(name).item("filename")
else
getfilepathcomplete = ""
end if
end function
public function getfilesize(name)
if dict.exists(name) then
getfilesize = lenb(dict(name).item("value"))
else
getfilesize = 0
end if
end function
public function getfilesizetranslated(name)
if dict.exists(name) then
temp = lenb(dict(name).item("value"))
if temp <= 1024 then
getfilesizetranslated = temp & " bytes"
else
temp = formatnumber((temp / 1024), 2)
getfilesizetranslated = temp & " kilobytes"
end if
else
getfilesizetranslated = ""
end if
end function
public function getcontenttype(name)
if dict.exists(name) then
getcontenttype = dict(name).item("contenttype")
else
getcontenttype = ""
end if
end function
private sub getdata(rawdata)
dim separator
separator = midb(rawdata, 1, instrb(1, rawdata, chrb(13)) - 1)
dim lenseparator
lenseparator = lenb(separator)
dim currentpos
currentpos = 1
dim instrbyte
instrbyte = 1
dim value, mvalue
dim tempvalue
tempvalue = ""
while instrbyte > 0
instrbyte = instrb(currentpos, rawdata, separator)
mvalue = instrbyte - currentpos
if mvalue > 1 then
value = midb(rawdata, currentpos, mvalue)
dim begpos, endpos, midvalue, nvalue
dim intdict
set intdict = server.createobject("scripting.dictionary")
begpos = 1 + instrb(1, value, chrb(34))
endpos = instrb(begpos + 1, value, chrb(34))
nvalue = endpos
dim namen
namen = midb(value, begpos, endpos - begpos)
dim namevalue, isvalid
isvalid = true
if instrb(1, value, stringtobyte("content-type")) > 1 then
begpos = 1 + instrb(endpos + 1, value, chrb(34))
endpos = instrb(begpos + 1, value, chrb(34))
if endpos = 0 then
endpos = begpos + 1
isvalid = false
end if
midvalue = midb(value, begpos, endpos - begpos)
intdict.add "filename", trim(bytetostring(midvalue))
begpos = 14 + instrb(endpos + 1, value, stringtobyte("content-type:"))
endpos = instrb(begpos, value, chrb(13))
midvalue = midb(value, begpos, endpos - begpos)
intdict.add "contenttype", trim(bytetostring(midvalue))
begpos = endpos + 4
endpos = lenb(value)
namevalue = midb(value, begpos, ((endpos - begpos) - 1))
else
namevalue = trim(bytetostring(midb(value, nvalue + 5)))
end if
if isvalid = true then
intdict.add "value", namevalue
intdict.add "name", namen
dict.add bytetostring(namen), intdict
end if
end if
currentpos = lenseparator + instrbyte
wend
end sub
end class
private function stringtobyte(toconv)
dim tempchar
for i = 1 to len(toconv)
tempchar = mid(toconv, i, 1)
stringtobyte = stringtobyte & chrb(ascb(tempchar))
next
end function
private function bytetostring(toconv)
for i = 1 to lenb(toconv)
bytetostring = bytetostring & chr(ascb(midb(toconv,i,1)))
next
end function
%>
1、用户界面:
复制代码 代码如下:
<script language="javascript">
function checkall(form)
{for (var i=0;i<form.elements.length;i++)
{var e = form.elements[i];
if (e.name != 'chkall')
e.checked = form.chkall.checked;
}
}
</script>
</head>
<body>
<form method="post" action="del.asp" name="form1">
<table>
<tr>
<td ><input type="checkbox" value="111" name="tradename">电子邮件1</td>
</tr>
<tr>
<td ><input type="checkbox" value="111" name="tradename">电子邮件2</td>
</tr>
<tr>
<td ><input type="checkbox" value="111" name="tradename">电子邮件3</td>
</tr>
<tr>
<td ><input type="checkbox" value="111" name="tradename">电子邮件4</td>
</tr>
<tr>
<td ><input type="checkbox" value="111" name="tradename">电子邮件5</td>
</tr>
<tr>
<td ><input type="checkbox" value="111" name="tradename">电子邮件6</td>
</tr>
<tr>
<td bgcolor="#f1fbfc" height="25" colspan="2">
<p align="left"><input type="checkbox" name="chkall" value="on" onclick="checkall(this.form)"><font color="#ff9900">选中所有显示的消息</font></p>
</td>
<center>
</tr>
</table>
</form>
2、删除文件del.asp
<%
'这行写连接数据库的代码
dim id,strid
strid=""
for each strid in request.form("tradename")
id=cint(strid)
if strid<>"" then
delrs = server.createobject("adodb.recordset")
conn.execute "delete from tbname where id="&cstr(id)
strid=""
end if
next
conn.close
set conn = nothing
response.redirect "成功删除!"
%>
上一篇: 一文读懂资产数字化大趋势的底层逻辑
推荐阅读