当前位置: 移动技术网 > IT编程>开发语言>Asp > 浏览文件夹下面所有图片

浏览文件夹下面所有图片

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<%
'+-----------------------------------+
'|     变量设置
'+-----------------------------------+
ctitle =   "所有上传图片(注:以下为图片文件夹下面所有图片,并非全部为有效图片!)"   '名字
cpictype =   "jpeg,jpg,gif,png,bmp"   '图片类型   (使用","将图片格式分开)
cheight =   120   '缩图高度
cwidth =   120   '缩图宽度
ceachlinemax =   5 '每行显示图片数
ceachpagemax =   20   '每页显示图片数目
pic_path="/uploadpic/" '设定图片所在路径
'+-----------------------------------+
'|     定义函数
'+-----------------------------------+
function   getext(name)
getext   =   right(name,   3)
end   function

function   ispic(filename,   pictype)
ext   =   getext(filename)
ispic   =   false
typelist   =   split(pictype,   ",")
for   ii   =   lbound(typelist)   to   ubound(typelist)
if   ucase(ext)   =   ucase(typelist(ii))   then
ispic   =   true
exit   for
end   if
next
end   function

function   pagebar(page,   pagetotal)
response.write   "[   <a   href="&request.servervariables("script_name")&"?page="   &   (page   -   1)   &   "   title=上一页>上一页</a>   ] "
response.write   "<a   href="&request.servervariables("script_name")&"?page=1     title=首页><<   </a>"
i   =   pagestart
do   while   i   <   page
response.write   "<a   href="&request.servervariables("script_name")&"?page="   &   i   &   "   title=""第   "   &   i   &   "   页"">["   &   i   &   "]</a> "
i   =   i   +   1
loop
response.write   "[<font   color=red><b>"   &   page   &   "</b></font>]"
i   =   pagemiddle
do   while   i   <=   pageend
response.write   "<a   href="&request.servervariables("script_name")&"?page="   &   i   &   "   title=""第   "   &   i   &   "   页"">["   &   i   &   "]</a> "
i   =   i   +   1
loop
response.write   "...<a   href="&request.servervariables("script_name")&"?page="   &   pagetotal   &   "   title=""第   "   &   pagetotal   &   "   页"">["   &   pagetotal   &   "]</a>"
response.write   "   <a   href="&request.servervariables("script_name")&"?page="   &   pagetotal   &   "   title=尾页>>></a>"
response.write   "[   <a   href="&request.servervariables("script_name")&"?page="   &   (page   +   1)   &   "   title=下一页>下一页</a>   ] 共   <b><font   color=red>"   &   pagetotal   &   "</font></b>   页  当前所在第   <b><font   color=red>"   &   page   &   "</font></b>   页   图片数   :   <b><font   color=red>"   &   pictotal   &   "</font></b>"
end   function
'+-----------------------------------+
'|     取图片尺寸类
'+-----------------------------------+
class   possible
  dim   aso
  private   sub   class_initialize
    set   aso=createobject("adodb.stream")
    aso.mode=3   
    aso.type=1   
    aso.open   
  end   sub
  private   sub   class_terminate
    set   aso=nothing
  end   sub
  private   function   bin2str(bin)
    dim   k,   str
    for   k=1   to   lenb(bin)
      clow=midb(bin,k,1)
      if   ascb(clow)<128   then
        str   =   str   &   chr(ascb(clow))
      else
        k=k+1
        if   k   <=   lenb(bin)   then   str   =   str   &   chr(ascw(midb(bin,k,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
    ret   =   0
    for   k=1   to   len(str)
      ret   =   ret   *base   +   cint(mid(str,k,1))
    next
    str2num=ret
  end   function

  private   function   binval(bin)
    dim   ret
    ret   =   0
    for   k   =   lenb(bin)   to   1   step   -1
      ret   =   ret   *256   +   ascb(midb(bin,k,1))
    next
    binval=ret
  end   function

  private   function   binval2(bin)
    dim   ret
    ret   =   0
    for   k   =   1   to   lenb(bin)
      ret   =   ret   *256   +   ascb(midb(bin,k,1))
    next
    binval2=ret
  end   function

  private   function   getimagesize(filespec)   
    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 
function   readx(pic_path)
      set   fso1   =   server.createobject("scripting.filesystemobject")
      set   f1   =   fso1.getfile(pic_path)
      ext=fso1.getextensionname("."&pic_path)
      select   case   ucase(ext)
          case   "gif","bmp","jpg","png":
        arr=getimagesize(f1.path)
        readx   =   arr(1)
          case   "swf"
        arr=pp.getimagesize(f1.path)
        readx   =   arr(1)
      end   select
      set   f1=nothing
      set   fso1=nothing
  end   function
  function   ready(pic_path)
      set   fso1   =   server.createobject("scripting.filesystemobject")
      set   f1   =   fso1.getfile(pic_path)
      ext=fso1.getextensionname("."&pic_path)
      select   case   ucase(ext)
          case   "gif","bmp","jpg","png":
        arr=getimagesize(f1.path)
        ready   =   arr(2)
          case   "swf"
        arr=pp.getimagesize(f1.path)
        ready   =   arr(2)
      end   select
      set   f1=nothing
      set   fso1=nothing
  end   function
end   class
'+-----------------------------------+
'|     数据处理
'+-----------------------------------+
dim   filearray()
redim   filearray(0)
set   fileobj =   server.createobject("scripting.filesystemobject")
set   folderobj =   fileobj.getfolder(server.mappath("."&pic_path))
i   =   0
for   each   file   in   folderobj.files
if   ispic(file.name,   cpictype)   then
filearray(i)   =   file.name
i   =   i   +   1
redim   preserve   filearray(i)
end   if 
next
set   fileobj =   nothing
set   folderobj =   nothing
pictotal   =   ubound(filearray)
'+-----------------------------------+
'|     分页处理
'+-----------------------------------+
page   =   int(request.querystring("page"))
pagetotal   =   -(int(-(pictotal/ceachpagemax)))
if   page   =   empty   or   page   <   0   then   page   =   1
if   page   >   pagetotal   then   page   =   pagetotal
offset   =   ceachpagemax   *   page
start   =   offset   -   ceachpagemax
if   start   <   0   then   start   =   0
if   offset   >   pictotal   then   offset   =   pictotal
pagestart   =   page   -   ceachpagemax
if   pagestart   <=   0   then   pagestart   =   1
pagemiddle   =   page   +   1
pageend   =   pagemiddle   +   ceachpagemax
if   page   <=   ceachpagemax   then   pageend   =   ceachpagemax   *   2
if   pageend   >   pagetotal   then   pageend   =   pagetotal
'+-----------------------------------+
'|     输出部分
'+-----------------------------------+
%>
<!doctype   html   public   "-//w3c//dtd   html   4.0   transitional//en">
<html>
<head>
<title>   <%=ctitle%>   </title>
<style   type='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:   12px   verdana;   color:#333333;   font-family:   tahoma,verdana,   tahoma,   arial,helvetica,   sans-serif;   font-size:   12px;   color:   #000;   margin:0px   12px   0px   12px;background-color:#fff   }
td   {font:   12px   verdana;   color:#333333;   font-family:   tahoma,verdana,   tahoma,   arial,helvetica,   sans-serif;   font-size:   12px;   color:   #000;   };
</style>
</head>
<body topmargin="0" leftmargin="0">
<script>
tpopwait=20;
showpopstep=10;
popopacity=85;
spop=null;
curshow=null;
tfadeout=null;
tfadein=null;
tfadewaiting=null;
document.write("<style   type='text/css'id='defaultpopstyle'>");
document.write(".cpoptext   {   font-family:   verdana,   tahoma;   background-color:   #f7f7f7;   border:   1px   #000000   solid;   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("<div   id='poplayer'   style='position:absolute;z-index:500;'   class='cpoptext'></div>");
function   showpopuptext(){
var   o=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==null   ||   spop=="")   {
poplayer.innerhtml="";
poplayer.style.filter="alpha()";
poplayer.filters.alpha.opacity=0; 
}   else   {
if(o.dyclass!=null)   popstyle=o.dyclass   
else   popstyle="cpoptext";
curshow=settimeout("showit()",tpopwait);
}
}
}
function   showit()   {
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
else   popleftadjust=0;
if(mousey+12+popheight>document.body.clientheight)   poptopadjust=-popheight-24
else   poptopadjust=0;
poplayer.style.left=mousex+12+document.body.scrollleft+popleftadjust;
poplayer.style.top=mousey+12+document.body.scrolltop+poptopadjust;
poplayer.style.filter="alpha(opacity=0)";
fadeout();
}
function   fadeout(){
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>
<%   pagebar   page,   pagetotal   %>
<br><br>
<table   border="0"   cellpadding="4"   cellspacing="4">
<tr>
<%
'+-----------------------------------+
'|     循环输出图片
'+-----------------------------------+
j   =   1
i   =   start
set   pp   =   new   possible
do   while   i   <   offset
thispicpath   =   server.mappath("."&pic_path  &   filearray(i))
x   =   pp.readx(thispicpath)
y   =   pp.ready(thispicpath)
if   x   >   cwidth   or   y   >   cheight   then
twidth   =   x   /   cwidth   :   theight   =   y   /   cheight
if   twidth   >   theight   then
w   =   cwidth
h   =   y   /   twidth
elseif   twidth   <   theight   then
h   =   cheight
w   =   x   /   theight
else
w   =   cwidth
h   =   cheight
end   if
else
w   =   x
h   =   y
end   if
if   j   >   ceachlinemax   then
j   =   1
response.write   "</tr><tr>"
end   if
response.write   "<td   style=""border:   1px   solid   #000000""   width="   &   cwidth   &   "   height="   &   cheight   &   "   align=center><a   href=""./"&pic_path &   filearray(i)   &   """   target=""_blank""><img   border=0   src="   & "."& pic_path& filearray(i)   &   "   width="   &   w   &   "   height="   &   h   &   "   alt=""文件:"   &   filearray(i)   &   "  <br>  尺寸:"   &   x   &   "   ×   "   &   y   &   "  ""></a></td>"
j   =   j   +   1
i   =   i   +   1
loop
set   pp   =   nothing
%>
</tr>
</table>
<br>
<%   pagebar   page,   pagetotal   %>
</center>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网