您的位置:首页 > 数据库

用fso将文件名和路径写入数据库实现文件(软件,视频,音频)添加自动化

2009-08-30 17:26 645 查看
单位要开vod和音乐点播服务,网站容易做,但下载下来的海量的电影和歌曲要往后台添加,委实是一项巨大的工程!谁愿意在这上面浪费青春呢。

看了fso强大的功能,我想到既然能读出文件名,为什么就不能将其写入数据库呢。经过了N(N>20)次的试验,暂时成了现在这个样子。我将逐步完善。先保存到这啦,呵呵!
以下文件在同一目录下:

数据库funonews.mdb里面有表admin
字段为:id(自动),admin,password,aleave
我要将e:/wwwroot/wwwroot/002下的所有文件添加到数据库中(具体路径你可以根据自己的需要修改。与本文中的文件路径没关系。但有个前提:你的机子必须支持FSO,具体可以看我的上一篇文章)

1. admin_admin.asp

<!--#include file="adminconn.inc" -->
<%
if session("aleave")="" then
response.redirect "adminlogin.asp"
response.end
end if
%>
<html>
<head>
<title>山西大同大学人事处</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="keywords" content="山西大同大学人事处">
<link rel="stylesheet" href="../css.css" type="text/css">
</head>
<body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="50" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#C6C6C6">
<tr align="center" bgcolor="#CCCCCC">
<td width="15%" height="24"> ID</td>
<td width="15%">用户</td>
<td width="20%">密码(<font color="#666666">加密</font>)</td>
<td width="20%">权限</td>
<td width="15%">修改</td>
<td width="15%">删除</td>
</tr>
<%
Set rs=Server.CreateObject("ADODB.RecordSet")
sql="select * from admin order by id"
rs.Open sql,conn,1,1
while not rs.eof
if rs("aleave")="super" then aleave="超级管理员" end if
if rs("aleave")="check" then aleave="普通管理员" end if
%>
<tr align="center" bgcolor="#FFFFFF">
<td height="22"><%=rs("id")%></td>
<td><%=rs("admin")%></td>
<td><%=rs("password")%></td>
<td><%=aleave%></td>
<td><a href="admin_AdminModify.asp?id=<%=rs("id")%>">修改</a></td>
<td><a href="admin_AdminDel.asp?id=<%=rs("id")%>">删除</a></td>
</tr>
<%
rs.movenext
wend
rs.close
set rs=nothing
%>
</table>
<br>
<table width="500" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#C6C6C6">
<tr bgcolor="#CCCCCC">
<td colspan="2">添加管理员:</td>
</tr>
<!--------------------------->
<%
path="e:/wwwroot/wwwroot/002"
Set fso = CreateObject("Scripting.FileSystemObject")
set fd=FSO.GetFolder(path)
count=fd.files.count-1
redim fileinfo(count,1)
i=0
for each file in fd.files
fileinfo(i,0)=file.name
fileinfo(i,1)=file.DateCreated
i=i+1
next
for i=0 to count-1
for j=i+1 to count
if cdate(fileinfo(i,1))<cdate(fileinfo(j,1)) then
tmpdate=fileinfo(i,1)
tmpfile=fileinfo(i,0)
fileinfo(i,1)=fileinfo(j,1)
fileinfo(i,0)=fileinfo(j,0)
fileinfo(j,1)=tmpdate
fileinfo(j,0)=tmpfile
end if
next
next
for i=0 to count%>

<%set savebbs=conn.execute("insert into admin(admin,aleave,password)values('"&fileinfo(i,1)&"','"&fileinfo(i,1)&"','"&fileinfo(i,1)&"')")%>

<%
set savebbs=nothing
%>

<%next
set fd=nothing
Set fso =nothing
%>

</table>
<br>
</td>
</tr>
</table>
</body>
</html>

2.adminconn.inc

<%
StrSQL="DBQ="+server.mappath("funonews.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open StrSQL
sub CloseConn()
conn.close
set conn=nothing
end sub
function decrypt(dcode)
dim texts
dim i
for i=1 to len(dcode)
texts=texts & chr(asc(mid(dcode,i,2))-i)
next
decrypt=texts
end function
function encrypt(ecode)
Dim texts
dim i
for i=1 to len(ecode)
texts=texts & chr(asc(mid(ecode,i,2))+i)
next
encrypt = texts
end function
%>

3.adminlogin.asp

<%
if request("logout")<>"" then
session("admin")=""
session("password")=""
session("aleave")=""
response.redirect "adminlogin.asp"
end if
%>
<html>
<head>
<LINK href="../css.css" type=text/css rel=stylesheet>
<title>山西大同大学人事处</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="keywords" content="山西大同大学人事处">
</head>

<body bgcolor="#F7F3F7" text="#000000">
<TABLE align=center bgColor=#DEDFDE cellpadding="4" cellspacing="0" border=0 style="border: outset 2px;width:60%;">
<TR>
<TD height=21 align="center" style="FILTER: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#003399', endColorStr='#AEC0EC', gradientType='1')"><b><font color=#FFFFFF>山西大同大学人事处管理中心登陆----Administer
Login</FONT></b></td>
</tr>
<TR>
<td width="100%"> <center>
<table cellspacing="0" cellpadding="0" width="558" border="0" style="border-collapse: collapse" bordercolor="#111111" height="237">
<tbody>
<tr>
<td valign="top" width="100%" height="104"><br>
<table width="240" border="0" align="center" cellpadding="0" cellspacing="0">
<form method=post action="chklogin.asp">
<tr>
<td width="100%" height="60" align="center" valign="middle">用户名:
<input class="input" style="color: #FF0000; background-color: #FFFFFF; border: 1px solid #000000" size="12" name="admin">
</td>
</tr>
<tr>
<td width="100%" height="60" align="center" valign="middle">密 码:
<input class="input" style="color: #FF0000; background-color: #FFFFFF; border: 1px solid #000000" type="password" size="12" name="password">
</td>
</tr>
<tr>
<td width="100%" height="30" align="center" valign="middle">
<input class="input" style="color: #FFFFFF; background-color: #FF0000; border: 1px solid #000000" type="submit" value="确 定" name="Submit">
    <input class="input" style="color: #FFFFFF; background-color: #FF0000; border: 1px solid #000000" type="reset" value="取 消" name="Submit2">
</td>
</tr>
</form>
</table></td>
</tr>
<tr>
<td valign="top" width="100%" height="10"> </td>
</tr>
</tbody>
</table>
</center></td>
</tr>
</table>
<br>
</body>
</html>

4.CHKLOGIN.ASP

<!--#include file="adminconn.inc" -->
<%
dim rs
admin1=request("admin")
password1=request("password")
set rs=server.CreateObject("ADODB.RecordSet")
rs.open "select * from admin where admin='" & admin1 & "' and password='"&encrypt(password1)&"'",conn,1
if rs.eof and rs.bof then
response.write"<SCRIPT language=JavaScript>alert('用户名或密码不正确!');"
response.write"javascript:history.go(-1)</SCRIPT>"
response.end
else
session("admin")=rs("admin")
session("password")=rs("password")
session("aleave")=rs("aleave")
response.redirect "admin_admin.asp"
end if
rs.close
set rs=nothing
%>
--------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: