用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
%>
--------------------------------
看了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
%>
--------------------------------
相关文章推荐
- java实现文件名,路径,日期,文件大小的统计并存入数据库
- os开发之如何添加多媒体文件(音频,视频)
- java+sql应用(数据库中音频,视频文件插入与读取)
- nio实现文件读取写入数据库或文件
- IOS成长之路-添加数据库文件到应用程序路径中
- php实现文件上传到指定文件夹,文件路径或名字存入数据库,如何实现啊
- asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
- ffmpeg 实现转码一个普通视频文件为视频mpeg4,音频mp3的功能的程序(摘)
- 视频网站的视频文件下载软件设计和实现(一)
- 使用VC实现读取指定路径下的文件,并显示所有文件的文件名和文件图标
- CuteEditor文件上传获取具体路径并写入数据库
- 使用批处理实现解析文本数据文件写入数据库表
- 实现用FFmpeg接收RTSP,把H264视频和AAC音频录制成MP4文件(附完整代码)
- VC——通过数据库存放路径来播放音频文件
- mongo数据库上传多媒体文件(视频/音频)文件问题
- Android对彩信数据库添加彩信(图片,音频,视频,文字)
- asp.net中使用Global.asax文件中添加应用出错代码,写入系统日志文件或数据库
- java 实现视频转换通用工具类:视频加水印-通过Avs文件添加视频水印(五-2)
- 文件上传控件Fileupload(实现文件上传并写入数据库)