最新图片上传编码问题

时间:2009-12-04 14:41:31

标签: image asp.net-2.0

有谁能帮我理解下面的asp.net 2.0编码? 它应该向我展示我上传到photoalbum中特定文件夹的几张最新照片。 但是,当我在已经有图像的文件夹中上传新文件时......使用该代码时显示的图像是此文件夹中的第一个图像... 有时候没有任何东西出现......

<%
latestfolder = "na"
latestdate = cdate("01/01/09")

set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(Server.MapPath("images/gallery"))

for each folder in fo.subfolders 
    if cdate(folder.DateLastModified) > latestdate then
        latestdate = cdate(folder.DateLastModified)
        latestfolder = folder.name
    end if
next

if latestfolder <> "na" then
    set fi=fs.GetFolder(Server.MapPath("images/gallery/" & latestfolder))
    looptimes = 0

    for each file in fi.files 
        if month(file.DateLastModified) = month(latestdate) then
            if right(lcase(file.Name),3) = "jpg" then %>
                <a href="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank"  style="text-decoration:none; cursor:pointer;">
                    <img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=100&maxHeight=60" style="border:1px solid #ffffff; margin:5px; margin-top:14px;">
                </a>        
            <% end if 
        end if

        looptimes = looptimes + 1
        if looptimes = 6 then exit for end if

    next

end if
%>
希望有些人可以帮助我:)。

2 个答案:

答案 0 :(得分:1)

以下代码看起来正在拾取当月的所有JPEG文件:

if month(file.DateLastModified) = month(latestdate) then
    if right(lcase(file.Name),3) = "jpg" then%>
        ...
    <% end if
end if

答案 1 :(得分:0)

当它循环遍历文件时,它会检查图像的上次修改日期是否与文件夹的上次修改日期相匹配。这是该专辑的“几张最新照片”的原始编码器定义。它还确保永远不会超过6个。

如果您不经常上传照片,则每次只能拍摄一张照片。如果你根本没有得到任何照片,你可能在该文件夹中做了其他的事情,这将改变其上次修改日期,而不添加任何照片。

我会考虑摆脱月份标准,并坚持使用6张照片限制,即替换

    if month(file.DateLastModified) = month(latestdate) then
        if right(lcase(file.Name),3) = "jpg" then %>
            <a href="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank"  style="text-decoration:none; cursor:pointer;">
                <img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=100&maxHeight=60" style="border:1px solid #ffffff; margin:5px; margin-top:14px;">
            </a>        
        <% end if 
    end if

    if right(lcase(file.Name),3) = "jpg" then %>
        <a href="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank"  style="text-decoration:none; cursor:pointer;">
            <img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=100&maxHeight=60" style="border:1px solid #ffffff; margin:5px; margin-top:14px;">
        </a>        
    <% end if