| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1731 人关注过本帖
标题:[求助]请教一个问题:ASP如何实现遍历文件夹中图片文件,并按照时间顺序显示?
只看楼主 加入收藏
smqxren
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-7-16
收藏
 问题点数:0 回复次数:4 
[求助]请教一个问题:ASP如何实现遍历文件夹中图片文件,并按照时间顺序显示?

<%

'+-----------------------------------+
'| 变量设置
'+-----------------------------------+

cTitle = "图显示系统" '名字
cPicType = "jpeg,jpg,gif,png,bmp" '图片类型 (使用","将图片格式分开)
cHeight = 480 '缩图高度
cWidth = 720 '缩图宽度
cEachLineMax = 1 '每行显示图片数
cEachPageMax = 1 '每页显示图片数目

'+-----------------------------------+
'| 定义函数
'+-----------------------------------+

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=default.asp?page=" & (page - 1) & " title=上一张>上一张</A> ]&nbsp;"
response.Write "<A HREF=default.asp?page=1 title=第一张><< </A>"

i = pageStart
Do while i < page
response.Write "<A HREF=default.asp?page=" & i & " title=""第 " & i & " 张"">[" & i & "]</A>&nbsp;"
i = i + 1
Loop

response.Write "[<FONT COLOR=red><B>" & page & "</B></FONT>]"

i = pageMiddle
Do while i <= pageEnd
response.Write "<A HREF=default.asp?page=" & i & " title=""第 " & i & " 张"">[" & i & "]</A>&nbsp;"
i = i + 1
Loop

response.Write "...<A HREF=default.asp?page=" & pageTotal & " title=""第 " & pageTotal & " 张"">[" & pageTotal & "]</A>"
response.Write " <A HREF=default.asp?page=" & pageTotal & " title=最末张>>></A>"
response.Write "[ <A HREF=default.asp?page=" & (page + 1) & " title=下一张>下一张</A> ]&nbsp;共 <B><FONT COLOR=red>" & pageTotal & "</FONT></B> 张&nbsp;&nbsp;当前所在第 <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("./"))

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>
<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:1000;' 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>&nbsp;&nbsp;'+sPop+'&nbsp;&nbsp;<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>
<center>
<%=cTitle%>
<br>
<font color="#FF0000">使用说明:。</font>
<table border="0" CELLPADDING="4" CELLSPACING="4">
<tr>
<%

'+-----------------------------------+
'| 循环输出图片
'+-----------------------------------+

j = 1
i = start
Set pp = New possible

Do While i < offset

thisPicPath = server.mappath("./" & 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=""./" & fileArray(i) & """ target=""_blank""><img border=0 src=" & fileArray(i) & " width=" & w & " height=" & h & " alt=""文件:" & fileArray(i) & "&nbsp;&nbsp;<br>&nbsp;&nbsp;尺寸:" & x & " × " & y & "&nbsp;&nbsp;""></a></td>"

j = j + 1

i = i + 1

Loop

Set pp = Nothing

%>
</tr>
</table>
<br>
<% pageBar page, pageTotal %>
</center>
</body>
</html>

以上是我在网上DOWN的一段源码,但这个源码我没看懂其显示顺序是在哪里进行的?
哪为大大能指点下,并能够帮我将显示顺序改成按照时间先后进行逆序显示,也就是新上传的先显示.

搜索更多相关主题的帖子: 遍历 顺序 ASP 文件 
2007-07-16 17:09
rtc
Rank: 2
等 级:新手上路
威 望:4
帖 子:590
专家分:0
注 册:2007-6-6
收藏
得分:0 
sql那句
sql="select form 表名 order by date desc"
date 库里的时间
2007-07-16 17:25
rtc
Rank: 2
等 级:新手上路
威 望:4
帖 子:590
专家分:0
注 册:2007-6-6
收藏
得分:0 
还有一点
别人写的程序,.没意思,.
自己写吧,.
一点一点的来
2007-07-16 17:26
smqxren
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-7-16
收藏
得分:0 
这里面根本没SQL语句啊,这是一个直接遍历文件夹图片的程序啊!!
a href=""./" & fileArray(i) & """ target=""_blank""
是不是该在这里下手改点什么啊??
2007-07-17 08:17
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 

.............

Dim fileArray()
reDim fileArray(0)
dim sq()
ReDim sq(0)

dim np
Dim so


Set fileObj = Server.CreateObject("Scripting.FileSystemObject")
Set folderObj = fileObj.GetFolder(server.MapPath("./"))

i = 0
j=0

For Each file in folderObj.Files
If isPIC(file.Name, cPicType) Then
sq(i)=file.datecreated
fileArray(i) = file.Name
i = i + 1
reDim Preserve fileArray(i)
ReDim preserve sq(i)
if i>1 Then
For j=i-1 To 1 Step -1
If DateDiff("s",CDate(sq(j)),CDate(sq(j-1)))<0 Then
so=fileArray(j)
fileArray(j)=fileArray(j-1)
fileArray(j-1)=so
np=sq(j)
sq(j)=sq(j-1)
sq(j-1)=np
End If
Next
End if
End if
Next

Set FileObj = Nothing
Set FolderObj = Nothing

...............

[此贴子已经被作者于2007-7-18 15:30:20编辑过]


其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2007-07-17 20:46
快速回复:[求助]请教一个问题:ASP如何实现遍历文件夹中图片文件,并按照时间顺序 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024066 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved