浏览文件夹下面所有图片

2018-09-06 12:39

阅读:504

  复制代码 代码如下:
<%
+-----------------------------------+
变量设置
+-----------------------------------+
cTitle=所有上传图片(注:以下为图片文件夹下面所有图片,并非全部为有效图片!)名字
cPicType=jpeg,jpg,gif,png,bmp图片类型(使用,将图片格式分开)
cHeight=120缩图高度
cWidth=120缩图宽度
cEachLineMax=5每行显示图片数
cEachPageMax=20每页显示图片数目
pic_path=/uploadpic/设定图片所在路径
+-----------------------------------+
定义函数
+-----------------------------------+
FunctiongetExt(name)
getExt=right(name,3)
EndFunction

FunctionisPIC(fileName,picType)
ext=getExt(fileName)
isPIC=False
typeList=split(picType,,)
Forii=LBound(typeList)ToUBound(typeList)
IfUCase(ext)=UCase(typeList(ii))Then
isPIC=True
ExitFor
EndIf
Next
EndFunction

FunctionpageBar(page,pageTotal)
response.Write[<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=&(page-1)&title=上一页>上一页</A>]
response.Write<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=1title=首页><<</A>
i=pageStart
Dowhilei<page
response.Write<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=&i&title=第&i&页>[&i&]</A>
i=i+1
Loop
response.Write[<FONTCOLOR=red><B>&page&</B></FONT>]
i=pageMiddle
Dowhilei<=pageEnd
response.Write<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=&i&title=第&i&页>[&i&]</A>
i=i+1
Loop
response.Write...<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=&pageTotal&title=第&pageTotal&页>[&pageTotal&]</A>
response.Write<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=&pageTotal&title=尾页>>></A>
response.Write[<AHREF=&Request.ServerVariables(SCRIPT_NAME)&?page=&(page+1)&title=下一页>下一页</A>]共<B><FONTCOLOR=red>&pageTotal&</FONT></B>页当前所在第<B><FONTCOLOR=red>&page&</FONT></B>页图片数:<B><FONTCOLOR=red>&picTotal&</FONT></B>
EndFunction
+-----------------------------------+
取图片尺寸类
+-----------------------------------+
Classpossible
dimaso
PrivateSubClass_Initialize
setaso=CreateObject(Adodb.Stream)
aso.Mode=3
aso.Type=1
aso.Open
EndSub
PrivateSubClass_Terminate
setaso=nothing
EndSub
PrivateFunctionBin2Str(Bin)
DimK,Str
ForK=1toLenB(Bin)
clow=MidB(Bin,K,1)
ifASCB(clow)<128then
Str=Str&Chr(ASCB(clow))
else
K=K+1
ifK<=LenB(Bin)thenStr=Str&Chr(ASCW(MidB(Bin,K,1)&clow))
endif
Next
Bin2Str=Str
EndFunction

PrivateFunctionNum2Str(num,base,lens)
dimret
ret=
while(num>=base)
ret=(nummodbase)&ret
num=(num-nummodbase)/base
wend
Num2Str=right(string(lens,0)&num&ret,lens)
EndFunction

PrivateFunctionStr2Num(str,base)
dimret
ret=0
fork=1tolen(str)
ret=ret*base+cint(mid(str,k,1))
next
Str2Num=ret
EndFunction

PrivateFunctionBinVal(bin)
dimret
ret=0
fork=lenb(bin)to1step-1
ret=ret*256+ascb(midb(bin,k,1))
next
BinVal=ret
EndFunction

PrivateFunctionBinVal2(bin)
dimret
ret=0
fork=1tolenb(bin)
ret=ret*256+ascb(midb(bin,k,1))
next
BinVal2=ret
EndFunction

PrivateFunctiongetImageSize(filespec)
dimret(3)
aso.LoadFromFile(filespec)
bFlag=aso.read(3)
selectcasehex(binVal(bFlag))
case4E5089:
aso.read(15)
ret(0)=PNG
ret(1)=BinVal2(aso.read(2))
aso.read(2)
ret(2)=BinVal2(aso.read(2))
case464947:
aso.read(3)
ret(0)=GIF
ret(1)=BinVal(aso.read(2))
ret(2)=BinVal(aso.read(2))
case535746:
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)
caseFFD8FF:
do
do:p1=binVal(aso.Read(1)):loopwhilep1=255andnotaso.EOS
ifp1>191andp1<196thenexitdoelseaso.read(binval2(aso.Read(2))-2)
do:p1=binVal(aso.Read(1)):loopwhilep1<255andnotaso.EOS
loopwhiletrue
aso.Read(3)
ret(0)=JPG
ret(2)=binval2(aso.Read(2))
ret(1)=binval2(aso.Read(2))
caseelse:
ifleft(Bin2Str(bFlag),2)=BMthen
aso.Read(15)
ret(0)=BMP
ret(1)=binval(aso.Read(4))
ret(2)=binval(aso.Read(4))
else
ret(0)=
endif
endselect
ret(3)=width=&ret(1)&height=&ret(2)&
getimagesize=ret
EndFunction
FunctionreadX(pic_path)
Setfso1=server.CreateObject(Scripting.FileSystemObject)
Setf1=fso1.GetFile(pic_path)
ext=fso1.GetExtensionName(.&pic_path)
selectcaseUCase(ext)
caseGIF,BMP,JPG,PNG:
arr=getImageSize(f1.path)
readX=arr(1)
caseswf
arr=pp.getimagesize(f1.path)
readX=arr(1)
endselect
Setf1=nothing
Setfso1=nothing
EndFunction
FunctionreadY(pic_path)
Setfso1=server.CreateObject(Scripting.FileSystemObject)
Setf1=fso1.GetFile(pic_path)
ext=fso1.GetExtensionName(.&pic_path)
selectcaseUCase(ext)
caseGIF,BMP,JPG,PNG:
arr=getImageSize(f1.path)
readY=arr(2)
caseswf
arr=pp.getimagesize(f1.path)
readY=arr(2)
endselect
Setf1=nothing
Setfso1=nothing
EndFunction
EndClass
+-----------------------------------+
数据处理
+-----------------------------------+
DimfileArray()
reDimfileArray(0)
SetfileObj=Server.CreateObject(Scripting.FileSystemObject)
SetfolderObj=fileObj.GetFolder(server.MapPath(.&pic_path))
i=0
ForEachfileinfolderObj.Files
fileArray(i)=file.Name
i=i+1
reDimPreservefileArray(i)
EndIf
Next
SetFileObj=Nothing
SetFolderObj=Nothing
picTotal=UBound(fileArray)
+-----------------------------------+
分页处理
+-----------------------------------+
page=int(Request.QueryString(page))
pageTotal=-(int(-(picTotal/cEachPageMax)))
Ifpage=Emptyorpage<0Thenpage=1
Ifpage>pageTotalThenpage=pageTotal
offset=cEachPageMax*page
start=offset-cEachPageMax
Ifstart<0Thenstart=0
Ifoffset>picTotalThenoffset=picTotal
pageStart=page-cEachPageMax
IfpageStart<=0ThenpageStart=1
pageMiddle=page+1
pageEnd=pageMiddle+cEachPageMax
Ifpage<=cEachPageMaxThenpageEnd=cEachPageMax*2
IfpageEnd>pageTotalThenpageEnd=pageTotal
+-----------------------------------+
输出部分
+-----------------------------------+
%>
<!doctypehtmlpublic-//W3C//DTDHTML4.0Transitional//EN>
<html>
<head>
<title><%=cTitle%></title>
<styletype=text/css>
a:link,a:visited,a:active{text-decoration:none;color:#000}
a:hover{color:orangered;text-decoration:none}
BODY{scrollbar-face-color:#DEE3E7;scrollbar-highlight-color:#FFFFFF;scrollbar-shadow-color:#DEE3E7;scrollbar-3dlight-color:#D1D7DC;scrollbar-arrow-color:#006699;scrollbar-track-color:#EFEFEF;scrollbar-darkshadow-color:#98AAB1;font:12pxVerdana;color:#333333;font-family:Tahoma,Verdana,Tahoma,Arial,Helvetica,sans-serif;font-size:12px;color:#000;margin:0px12px0px12px;background-color:#FFF}
TD{font:12pxVerdana;color:#333333;font-family:Tahoma,Verdana,Tahoma,Arial,Helvetica,sans-serif;font-size:12px;color:#000;};
</style>
</head>
<bodytopmargin=0leftmargin=0>
<script>
tPopWait=20;
showPopStep=10;
popOpacity=85;
sPop=null;
curShow=null;
tFadeOut=null;
tFadeIn=null;
tFadeWaiting=null;
document.write(<styletype=text/cssid=defaultPopStyle>);
document.write(.cPopText{font-family:Verdana,Tahoma;background-color:#F7F7F7;border:1px#000000solid;font-size:11px;padding-right:4px;padding-left:4px;height:20px;padding-top:2px;padding-bottom:2px;filter:Alpha(Opacity=0)});
document.write(</style>);
document.write(<divid=popLayerstyle=position:absolute;z-index:500;class=cPopText></div>);
functionshowPopupText(){
varo=event.srcElement;
MouseX=event.x;
MouseY=event.y;
if(o.alt!=null&&o.alt!=){o.pop=o.alt;o.alt=}
if(o.title!=null&&o.title!=){o.pop=o.title;o.title=}
if(o.pop){o.pop=o.pop.replace(\n,<br>);o.pop=o.pop.replace(\n,<br>);}
if(o.pop!=sPop){
sPop=o.pop;
clearTimeout(curShow);
clearTimeout(tFadeOut);
clearTimeout(tFadeIn);
clearTimeout(tFadeWaiting);
if(sPop==nullsPop==){
popLayer.style.filter=Alpha();
popLayer.filters.Alpha.opacity=0;
}else{
if(o.dyclass!=null)popStyle=o.dyclass
elsepopStyle=cPopText;
curShow=setTimeout(showIt(),tPopWait);
}
}
}
functionshowIt(){
popLayer.className=popStyle;
popLayer.innerHTML=<BR>+sPop+<BR><BR>;
popWidth=popLayer.clientWidth;
popHeight=popLayer.clientHeight;
if(MouseX+12+popWidth>document.body.clientWidth)popLeftAdjust=-popWidth-24
elsepopLeftAdjust=0;
if(MouseY+12+popHeight>document.body.clientHeight)popTopAdjust=-popHeight-24
elsepopTopAdjust=0;
popLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
popLayer.style.filter=Alpha(Opacity=0);
fadeOut();
}
functionfadeOut(){
if(popLayer.filters.Alpha.opacity<popOpacity){
popLayer.filters.Alpha.opacity+=showPopStep;
tFadeOut=setTimeout(fadeOut(),1);
}
}
document.onmouseover=showPopupText;
</script>
<br><br>
<center>
<%=cTitle%>
<br><br>
<%pageBarpage,pageTotal%>
<br><br>
<tableborder=0CELLPADDING=4CELLSPACING=4>
<tr>
<%
+-----------------------------------+
循环输出图片
+-----------------------------------+
j=1
i=start
Setpp=Newpossible
DoWhilei<offset
thisPicPath=server.mappath(.&pic_path&fileArray(i))
x=pp.readX(thisPicPath)
y=pp.readY(thisPicPath)
Ifx>cWidthory>cHeightThen
tWidth=x/cWidth:tHeight=y/cHeight
IftWidth>tHeightThen
w=cWidth
h=y/tWidth
ElseiftWidth<tHeightThen
h=cHeight
w=x/tHeight
Else
w=cWidth
h=cHeight
EndIf
Else
w=x
h=y
EndIf
Ifj>cEachLineMaxThen
j=1
response.Write</tr><tr>
EndIf
response.Write<tdstyle=border:1pxsolid#000000width=&cWidth&height=&cHeight&align=center><ahref=./&pic_path&fileArray(i)&><imgborder=0src=&.&pic_path&fileArray(i)&width=&w&height=&h&alt=文件:&fileArray(i)&<br>尺寸:&x&×&y&></a></td>
j=j+1
i=i+1
Loop
Setpp=Nothing
%>
</tr>
</table>
<br>
<%pageBarpage,pageTotal%>
</center>
</body>
</html>


评论


亲,登录后才可以留言!