上传文件时,怎样让上传后的文件名为当前时间(年月日时分秒)
Ft_admin_upload.asp代码如下:
<!--#include file="Ft_config.asp"-->
<form name="up" method="post" action="Ft_admin_upfile.asp" enctype="multipart/form-data" onSubmit="return chk1();">
<input name="img" type="file" size="10"> <input type="submit" name="submit2" value="上传" class="submit">
<span class="STYLE1">只能上传30K大小的文件(规格约为100×100)</span>
</form>
Ft_config.asp代码如下:
<%
'====="上传设置"=====
Const allowupfile="gif;txt;jpg;jpeg;png;bmp;rar;zip" '各扩展名以英文分号分隔!系统默认允许文件列表为:gif;txt;jpg;jpeg;png;bmp;rar;zip;txt
Const allowupfilesize=30720 '上传文件大小设置,单位为:KB,注意不能设置过大,WIN2003有200K上传大小限制
%>
Ft_admin_upfile.asp代码如下:
<!--#include file="Ft_admin_upfile_class.asp"-->
<%
dim upfile,upmax,updir,checkupfile,SaveFilename
'==================================
'=参数设置:
'upmax为上传文件大小,此处设置为300KB,计算方法为 307200/1024=300K,注意不能过大,否则影响后面的自动检测功能;
'updir为上传目录,按月分别建立,总目录在程序根目录下的FUploadFile中;
'checkupfile为检测函数使用开关,0为关闭,1为启用
'==================================
'upmax=307200
upmax=allowupfilesize
updir="FUploadFile/"
checkupfile=1 '检测函数使用开关,0为关闭,1为启用
set upfile=new upfile_class
upfile.GetData (upmax)
'检查上传文件夹
Dim chk
set chk = Server.CreateObject("Scripting.FileSystemObject")
if chk.FolderExists(Server.MapPath(updir)) =false then
chk.CreateFolder(Server.MapPath(updir))
end if
set chk=nothing
'执行保存文件代码
dim path,FSPath
FSPath=GetFilePath(Server.mappath("upfile.asp"),"\")'取得当前文件在服务器路径
FSPath=FSPath&updir
path =FSPath&upfile.File("img").filename
upfile.SaveToFile "img",path
select case upfile.isErr
case 1
Response.Write "你没有填写上传数据 [<a href='Ft_admin_upload.asp'>重新上传</a>]"
case 2
response.Write "文件过大,应小于"&upmax/1024&"KB [<a href='Ft_admin_upload.asp'>重新上传</a>]"
case 3
response.Write "该文件类型不允许上传 [<a href='Ft_admin_upload.asp'>重新上传</a>]"
case else
if checkupfile=1 then
'==================================
'=功能:自动检测上传文件是否含有非法代码
'=版本:feitec V1.0
'=作者:绯心剑客
'==================================
Dim objFSO,objTS,strText,ComStr,i,filebb,strArray
filebb=updir&upfile.file("img").filename
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath(filebb)) Then
Set objTS=objFSO.OpenTextFile(Server.MapPath(filebb),1)
strText=lcase(objTS.ReadAll)
objTS.Close
'禁止字符,可随时添加
ComStr="cookie|.getfolder|.createfolder|.deletefolder|.createdirectory|.deletedirectory|0n error resume next|站长助手|密码|海阳|adodb.stream|createobject|scripting.filesystemobject|strbackdoor|password|command.com"
ComStr=ComStr&"|.saveas|wscript.shell|shell.application|script.encode|folderpath|session|request|iframe|frame|execute|object|server.mappath"
strArray=split(ComStr,"|")
for i=0 to ubound(strArray)
if instr(strText,strArray(i))<>0 then
objFSO.DeleteFile Server.MapPath(filebb),True
response.write"<font color=red>非法文件,禁止上传!</font> [<a href='Ft_upload.asp'>重新上传</a>]"
response.end
end if
next
Set objFSO=nothing
else
response.write"该文件不存在"
end if
end if
response.write"<script>parent.Dvbbs_Composition.document.body.innerHTML+='<img src="&updir&upfile.file("img").filename &">'</script>"
'==================================
'代码检测结束
'==================================
response.Write "<font color=green style='font-size:12px'>上传成功!复制文件路径"&updir&upfile.file("img").filename &"到下面的文本框内 [<a href='Ft_admin_upload.asp'>继续上传</a>]</font>"
end select
set upfile=nothing
Function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
%>