Class ImgWHInfo '获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP
Dim ASO
Private Sub Class_Initialize
Set ASO=Server.CreateObject("ADODB.Stream")
ASO.Mode=3
ASO.Type=1
ASO.Open
End Sub
Private Sub Class_Terminate
Err.Clear
Set ASO=Nothing
End Sub
Private Function Bin2Str(Bin)
Dim I, Str
For I=1 To LenB(Bin)
clow=MidB(Bin,I,1)
If ASCB(clow)<128 Then
Str = Str &Chr(ASCB(clow))
Else
I=I+1
If I <= LenB(Bin) Then Str = Str &Chr(ASCW(MidB(Bin,I,1)&clow))
End If
Next
Bin2Str = Str
End Function
Private Function Num2Str(Num,Base,Lens)
Dim Ret
Ret = ""
While(Num>=Base)
Ret = (Num Mod Base) &Ret
Num = (Num - Num Mod Base)/Base
Wend
Num2Str = Right(String(Lens,"0") &Num &Ret,Lens)
End Function
Private Function Str2Num(Str,Base)
Dim Ret,I
Ret = 0
For I=1 To Len(Str)
Ret = Ret *base + Cint(Mid(Str,I,1))
Next
Str2Num=Ret
End Function
Private Function BinVal(Bin)
Dim Ret,I
Ret = 0
For I = LenB(Bin) To 1 Step -1
Ret = Ret *256 + AscB(MidB(Bin,I,1))
Next
BinVal=Ret
End Function
Private Function BinVal2(Bin)
Dim Ret,I
Ret = 0
For I = 1 To LenB(Bin)
Ret = Ret *256 + AscB(MidB(Bin,I,1))
Next
BinVal2=Ret
End Function
Private Function GetImageSize(filespec)
Dim bFlag
Dim Ret(3)
ASO.LoadFromFile(filespec)
bFlag=ASO.Read(3)
Select Case Hex(binVal(bFlag))
Case "4E5089":
ASO.Read(15)
ret(0)="PNG"
ret(1)=BinVal2(ASO.Read(2))
ASO.Read(2)
ret(2)=BinVal2(ASO.Read(2))
Case "464947":
ASO.read(3)
ret(0)="gif"
ret(1)=BinVal(ASO.Read(2))
ret(2)=BinVal(ASO.Read(2))
Case "535746":
ASO.read(5)
binData=ASO.Read(1)
sConv=Num2Str(ascb(binData),2 ,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
While(len(sConv)<nBits*4)
binData=ASO.Read(1)
sConv=sConv&Num2Str(AscB(binData),2 ,8)
Wend
ret(0)="SWF"
ret(1)=Int(Abs(Str2Num(Mid(sConv,1*nBits+1,nBits),2)-Str2Num(Mid(sConv,0*nBits+1,nBits),2))/20)
ret(2)=Int(Abs(Str2Num(Mid(sConv,3*nBits+1,nBits),2)-Str2Num(Mid(sConv,2*nBits+1,nBits),2))/20)
Case "FFD8FF":
Do
Do: p1=binVal(ASO.Read(1)): Loop While p1=255 And Not ASO.EOS
If p1>191 And p1<196 Then Exit Do Else ASO.read(binval2(ASO.Read(2))-2)
Do:p1=binVal(ASO.Read(1)):Loop While p1<255 And Not ASO.EOS
Loop While True
ASO.Read(3)
ret(0)="JPG"
ret(2)=binval2(ASO.Read(2))
ret(1)=binval2(ASO.Read(2))
Case Else:
If left(Bin2Str(bFlag),2)="BM" Then
ASO.Read(15)
ret(0)="BMP"
ret(1)=binval(ASO.Read(4))
ret(2)=binval(ASO.Read(4))
Else
ret(0)=""
End If
End Select
ret(3)="width=""" &ret(1) &""" height=""" &ret(2) &""""
getimagesize=ret
End Function
Public Function imgW(IMGPath)
Dim FSO,IMGFile,FileExt,Arr
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If (FSO.FileExists(IMGPath)) Then
Set IMGFile = FSO.GetFile(IMGPath)
FileExt=FSO.GetExtensionName(IMGPath)
Select Case FileExt
Case "gif","bmp","jpg","png":
Arr=GetImageSize(IMGFile.Path)
imgW = Arr(1)
End Select
Set IMGFile=Nothing
Else
imgW = 0
End If
Set FSO=Nothing
End Function
Public Function imgH(IMGPath)
Dim FSO,IMGFile,FileExt,Arr
Set FSO = server.CreateObject("Scripting.FileSystemObject")
If (FSO.FileExists(IMGPath)) Then
Set IMGFile = FSO.GetFile(IMGPath)
FileExt=FSO.GetExtensionName(IMGPath)
Select Case FileExt
Case "gif","bmp","jpg","png":
Arr=getImageSize(IMGFile.Path)
imgH = Arr(2)
End Select
Set IMGFile=Nothing
Else
imgH = 0
End If
Set FSO=Nothing
End Function
End Class
IMGPath="Test.jpg"
Set PP = New ImgWHInfo
W = PP.imgW(Server.Mappath(IMGPath))
H = PP.imgH(Server.Mappath(IMGPath))
Set pp = Nothing
Response.Write("<img src='"&IMGPath&"' border=0><br>宽:"&W&"高:"&H)
%>
Dim fsoSet fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile "C:\图片1.jpg", "D:\新建文件夹\"
fso.MoveFile "C:\图片2.jpg", "D:\新建文件夹 (2)\"
'其他的你不用改,MoveFile的第一个参数为文件的路径,第二个参数为要移动到的路径(注意:要移动到的路径的后面一定要加一个"\")
'………………
Set fso = Nothing
先复制你系统里面的cmd.exe和Rar.exe到网站目录SysRar下,没有则创建该目录调用相应函数即可实现,zip为压缩函数,UnZip为解压函数
这两个功能运行没有任何问题,不过我想在压缩文件时加个注释就没有成功过
我的问题在http://zhidao.baidu.com/question/347165075.html?oldq=1
如果你找到我问题的解决方案,请告诉我一声
<%
'压缩功能函数
Sub Zip()
Dim tmpSitePath
tmpSitePath = "www"
set fso=server.createobject("scripting.filesystemobject")
If fso.folderexists(server.mappath("/"&tmpSitePath)) = False Then
chkError = chkError &"你的网站目录找不到!\n\n"
Response.Write("<script language=""JavaScript"">alert(""提示:\n\n"&chkError&""")window.location.href='?Page="&Page&"&Keyword="&Keyword&"&Rd="&INT(8+1)*RND&"'</script>")
response.End
End If
if fso.FileExists(server.mappath("/"&tmpSitePath)&".rar") Then
fso.DeleteFile server.mappath("/"&tmpSitePath&".rar"),True
End If
If fso.folderexists(server.mappath("/Tmp"&tmpSitePath)) Then
fso.DeleteFolder(server.mappath("/Tmp"&tmpSitePath))
End If
fso.CreateFolder(server.mappath("/Tmp"&tmpSitePath))
fso.copyfolder server.mappath("/"&tmpSitePath),server.mappath("/Tmp"&tmpSitePath)
'----进行些相应的数据库COPY操作----
Server.ScriptTimeout=99999
Dim winrar,cmddir
Winrar=Server.Mappath("/SysRar/Rar.exe") '压缩文件(Winrar)的地址
cmddir=Server.Mappath("/SysRar/cmd.exe") 'cmd.exe(命令提示符)的地址
Set Shell = Server.CreateObject("WScript.Shell")
Runing= cmddir&" /c """&winrar&""" a -r -ibck -y -zReadMe.txt -ep1 -o+ -p"&tmpSitePath&" " '压缩 c -zReadMe.txt /cf 添加文件注释
Cmd=Runing&server.mappath("/"&tmpSitePath)&".rar "&server.mappath("/Tmp"&tmpSitePath&"/")&"\*.*"
Runcode = Shell.Run(Cmd,1,True)
Runing = Shell.Run(cmddir&" /c taskkill /im winrar.exe",1,false)
Runing = Shell.Run(cmddir&" /c exit",1,false)
Set Shell=Nothing
if not isempty(Runcode) and Runcode=0 Then
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile server.mappath("/"&tmpSitePath)&".rar"
ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachmentfilename="&tmpSitePath&".rar"
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
response.Clear()
objStream.Close
Set objStream = Nothing
if fso.FileExists(server.mappath("/"&tmpSitePath)&".rar ") Then
fso.DeleteFile server.mappath("/"&tmpSitePath&".rar "),True
End If
elseif not isempty(Runcode) then
Response.Write("操作执行失败!可能您的权限不够或者该程序无法在DOS(命令提示符)下运行,您提交的操作如下:<br>" &Cmd)
else
end if
If Err Then
Response.Write "<br>"&err.description
err.Clear
End If
If fso.folderexists(server.mappath("/Tmp"&tmpSitePath)) Then
fso.DeleteFolder(server.mappath("/Tmp"&tmpSitePath))
End If
Set fso =nothing
End Sub
'解压功能函数
Sub UnZip()
Call ChkSession()
Dim tmpSitePath
tmpSitePath = "www"
set fso=server.createobject("scripting.filesystemobject")
if fso.FileExists(server.mappath("/"&tmpSitePath)&".rar") = False Then
chkError = chkError &"你的Rar压缩文件找不到!\n\n"
Response.Write("<script language=""JavaScript"">alert(""友情提示:\n\n"&chkError&""")window.location.href='?Page="&Page&"&Keyword="&Keyword&"&Rd="&INT(8+1)*RND&"'</script>")
response.End
End If
If fso.folderexists(server.mappath("/"&tmpSitePath)) Then
fso.DeleteFolder(server.mappath("/"&tmpSitePath))
End If
fso.CreateFolder(server.mappath("/"&tmpSitePath))
Server.ScriptTimeout=99999
Dim winrar,cmddir
Winrar=Server.Mappath("/SysRar/Rar.exe")
cmddir=Server.Mappath("/SysRar/cmd.exe")
Set Shell = Server.CreateObject("WScript.Shell")
Runing= cmddir&" /c """&winrar&""" x -ibck -t -y -o+ -p"&tmpSitePath&" "
Cmd=Runing&server.mappath("/"&tmpSitePath)&".rar"&" "&server.mappath("/"&tmpSitePath)
Runcode = Shell.Run(Cmd,1,True)
Runing = Shell.Run(cmddir&" /c taskkill /im winrar.exe",1,false)
Runing = Shell.Run(cmddir&" /c exit",1,false)
Set Shell=Nothing
if not isempty(Runcode) and Runcode=0 Then
Response.Write("操作成功执行,您提交的操作如下:<br>"&Cmd)
if fso.FileExists(server.mappath("/"&tmpSitePath)&".rar ") Then
fso.DeleteFile server.mappath("/"&tmpSitePath&".rar "),True
End If
elseif not isempty(Runcode) then
Response.Write("操作执行失败!可能您的权限不够或者该程序无法在DOS(命令提示符)下运行,您提交的操作如下:<br>" &Cmd)
else
end If
Set fso =nothing
If Err Then
Response.Write "<br>"&err.description
err.Clear
End If
Response.Write("<script language=""JavaScript"">alert(""友情提示:\n\n解压成功,所有数据为最新压缩包数据"")window.location.href='?Page="&Page&"&Keyword="&Keyword&"&Rd="&INT(8+1)*RND&"'</script>")
End Sub
%>
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)