–
转移:
Set MyFileObject=Server.CreateObject(“Scripting.FileSystemObject”)
MyFileObject.CopyFile server.MapPath(“NewsFile”&sSaveFileName&””),server.MapPath(“”&sTitle&””&sSaveFileName&””) ”第一个是源路径,第二是目标路径,可为虚拟路径和物理路径。
创建并写入.htm文件:
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
Set oTextStream = oFSO.CreateTextFile(server.MapPath(“”&sTitle&””)&””&sTitle&”.htm”,true)
oTextStream.Write sContenta
oTextStream.Close
压缩文件:
Dim CmdDirr,RarNameDirr,RarSourceDirr
CmdDirr=Server.MapPath(“dos”)&”” ‘cmd.exe和rar.exe存放的路径
RarNameDirr=Server.MapPath(“content”)&””&sTitle&”” ‘压缩成rar的名字和路径
RarSourceDirr=Server.MapPath(“” & sTitle & “”)&”” ‘要压缩的文件路径和名字
Dim Cmd,Shell
Cmd=CmdDirr&”cmd.exe /c “&CmdDirr&”Rar.exe a -ep1 -o+ ” ‘ -ep1 -o+分别为两个开关命令具体可参考WinRar的帮助
Cmd=Cmd&RarNameDirr&” “&RarSourceDirr
On Error Resume Next
Set Shell = Server.CreateObject(“WScript.Shell”)
If Err or IsObject(Shell)=False Then
If Err Then Err.Clear
Response.Write “没有操作Shell权限…”
Response.End
End If
On Error Resume Next
Shell.Run Cmd,1,True
If Err Then
Err.Clear
Response.Write “压缩文件时出错,可能没有操作权限”
Response.End
End If
将压缩包写进数据库:
szFilepath =””&server.MapPath(“content”)&”/”&sTitle&”.rar” ‘压缩包的地址和名字
Set fso=Server.CreateObject(“Scripting.FileSystemObject”)
If fso.FileExists(szFilepath) Then ‘判断压缩文件是否存在
Set ffile=fso.GetFile(szFilepath)
If ffile.size > 0 Then ‘压缩文件是否为空
Dim objStream
Set objStream = Server.CreateObject(“ADODB.Stream”)
With objStream
.Type = 1
.Mode = 0
.Open
.LoadFromFile szFilepath
ors(“D_jdpath”).AppendChunk objStream.Read ‘写进数据库
.Close
End With
set objstream=nothing
Else
Response.Write “<script language=’javascript’>alert(‘文件不存在!’)</script>”
End If
Set ffile=Nothing
end if
从数据库中读出:
szFPath = server.MapPath(“./”)&””&title&”.rar” ‘压缩文件存放的地址
Set fso=createObject(“Scripting.FileSystemObject”)
IF fso.FileExists(szFPath) Then ‘判断压缩文件地址有没有冲突
fso.DeleteFile(szFPath)
End IF
Dim objStream
Set objStream = Server.CreateObject(“ADODB.Stream”)
With objStream
.Type = 1
.Mode = 0
.Open
.Write(rs(“D_jdpath”)) ‘从数据库里直接读出来,这里的数据库字段类型在MYSQL中为IMG在ACCESS中为OLE
.SaveToFile(szFPath)
.Close
End With
Set objStream = Nothing
解压文件:
dim ylj,ywj,Mlpath,Shell,rarcomm,RetCode,cmd,comm,fso
Mlpath=server.MapPath(“dos”)&”” ‘存放RAR.EXE和CMD.EXE的路径
ylj=Server.mappath(“data”)&”” ‘解压文件后所放的路径
ywj=Server.MapPath(“data”)&”MMGG.rar” ‘要解压的RAR文件
Set Shell = Server.CreateObject(“WScript.Shell”)
rarcomm=Mlpath&”cmd.exe /c “&Mlpath&”rar.exe x -t -o+ -p- “
cmd=rarcomm&ywj&” “&ylj
RetCode = Shell.Run(cmd,1, False)
完成!