Avatar billede bjuhl Nybegynder
29. juni 2003 - 18:02 Der er 2 kommentarer og
1 løsning

Billedgallery: Filer og biblioteker i koloner.

Dette billedgallery lister alle filer og biblioteker i én kolone.
Kan man ikke få den til at liste dem i kolonner med 15 i hver???

Denne streng skal ligge i en default.asp i roden af de biblioteker der skal vises.

<!-- #include file="gallery.asp" -->
<%=STVGallery(Request.Querystring("p"))%>

-------------------------------------------------------

<%
Function STVGallery(path)

    Dim ValidExt(4)
    ValidExt(0) = "jpg"
    ValidExt(1) = "gif"
    ValidExt(2) = "png"
    ValidExt(3) = "bmp"
    imgpath = "/pics/"

    On Error Resume Next
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    root = Server.Mappath(".")
    url = Request.ServerVariables("URL")
    webpath = left(url, instrrev(url, "/"))
    If path = "" or right(path, 1) = "/" or right(path, 1) = "\" then
        If instr(path, "/") > 0 then
            path = replace(path, "/", "\")
        End if
        If left(path, 1) <> "\" then
            path = "\" & path
        End if
        If right(path, 1) <> "\" then
            path = path & "\"
        End if
        If instr(path, "..") < 1 then
            uppath = left(replace(path, "\", "/"), instrrev(left(replace(path, "\", "/"), len(path)-1), "/"))
            If uppath = "" then
                uppath = "/"
            End if
            result = vbcrlf & "<!-- Begin STVGallery file list -->" & vbcrlf
            result = result & "<table border=""0"" cellspacing=""3"" cellpadding=""0"">" & vbcrlf
            result = result & "  <tr>" & vbcrlf
            result = result & "    <td width=""18"" align=""center""><a href=""" & webpath & "?p=" & uppath & """><img src=""" & imgpath & "folder_up.gif"" border=""0"" alt=""Tilbage""></a></td>" & vbcrlf
            result = result & "    <td nowrap><a href=""" & webpath & "?p=" & uppath & """>Tilbage</a></td>" & vbcrlf
            result = result & "  </tr>" & vbcrlf
            result = result & "  <tr>" & vbcrlf
            result = result & "    <td colspan=""2"" style=""height: 10px""></td>" & vbcrlf
            result = result & "  </tr>" & vbcrlf
            If FSO.FolderExists(root & path) then
                Set dir = FSO.GetFolder(root & path)
                Set subdirs = dir.SubFolders
                For each subdir in subdirs
                    If err.Number = 0 then
                        result = result & "  <tr>" & vbcrlf
                        result = result & "    <td align=""center""><a href=""" & webpath & "?p=" & replace(path, "\", "/") & subdir.name & "/""><img src=""" & imgpath & "folder.gif"" border=""0"" alt=""Folder""></a></td>" & vbcrlf & "    <td nowrap><a href=""" & webpath & "?p=" & replace(path, "\", "/") & subdir.name & "/"">" & subdir.name & "</a></td>" & vbcrlf
                        result = result & "  </tr>" & vbcrlf
                    Else
                        result = result & "  <tr>" & vbcrlf
                        result = result & "    <td></td><td>" & err.Description & "</td>" & vbcrlf
                        result = result & "  </tr>" & vbcrlf
                        err.Clear
                    End if
                Next
                Set subdirs = Nothing
                Set dirfiles = dir.Files
                For each dirfile in dirfiles
                    For ext = 0 to ubound(ValidExt)-1
                        If instr(right(lcase(dirfile), 4), ValidExt(ext)) > 0 then
                            result = result & "  <tr>" & vbcrlf
                            result = result & "    <td align=""center""><a href=""" & webpath & "?p=" & replace(path, "\", "/") & dirfile.name & """><img src=""" & imgpath & "file.gif"" border=""0"" alt=""File""></a></td>" & vbcrlf & "    <td nowrap><a href=""" & webpath & "?p=" & replace(path, "\", "/") & dirfile.name & """>" & dirfile.name & "</a></td>" & vbcrlf
                            result = result & "  </tr>" & vbcrlf
                        End if
                    Next
                Next
                Set dirfiles = Nothing
                Set dir = Nothing
            Else
                result = result & "  <tr>" & vbcrlf
                result = result & "    <td></td>" & vbcrlf
                result = result & "    <td nowrap>Path not found</td>" & vbcrlf
                result = result & "  </tr>" & vbcrlf
            End if
            result = result & "</table>" & vbcrlf
            result = result & "<!-- End STVGallery file list -->" & vbcrlf
        Else
            Response.Redirect(webpath)
        End if
    Else
        If instr(path, "/") > 0 then
            path = replace(path, "/", "\")
        End if
        If left(path, 1) <> "\" then
            path = "\" & path
        End if
        If instr(path, "..") < 1 then
            uppath = left(replace(path, "\", "/"), instrrev(left(replace(path, "\", "/"), len(path)-1), "/"))
            result = vbcrlf & "<!-- Begin STVGallery item display -->" & vbcrlf
            result = result & "<table border=""0"" cellspacing=""3"" cellpadding=""0"">" & vbcrlf
            result = result & "  <tr>" & vbcrlf
            result = result & "    <td width=""18"" align=""center""><a href=""" & webpath & "?p=" & uppath & """><img src=""" & imgpath & "folder_up.gif"" border=""0"" alt=""Up""></a></td>" & vbcrlf
            result = result & "    <td nowrap><a href=""" & webpath & "?p=" & uppath & """>Tilbage</a></td>" & vbcrlf
            result = result & "  </tr>" & vbcrlf
            result = result & "</table>" & vbcrlf
            If uppath = "" then
                uppath = "/"
            End if
            If FSO.FileExists(root & path) then
                Set imgfile = FSO.GetFile(root & path)
                imgname = imgfile.Name
                result = result & "<p align=""center""><a href=""" & webpath & "?p=" & replace(path, "\", "/") & """>" & imgname & "</a><br><br><img src=""" & webpath & right(replace(path, "\", "/"), len(path)-1) & """ alt=""" & imgname & """></p>" & vbcrlf
                Set imgfile = Nothing
                dirpath = left(path, len(path)-len(imgname))
                Set dir = FSO.GetFolder(root & dirpath)
                Set dirfiles = dir.Files
                counter = 0
                For each dirfile in dirfiles
                    For ext = 0 to ubound(ValidExt)-1
                        If instr(right(lcase(dirfile), 4), ValidExt(ext)) > 0 then
                            counter = counter + 1
                            If instr(dirfile, imgname) > 0 then
                                imgfileloc = counter
                            End if
                        End if
                    Next
                Next
                counter = 0
                For each dirfile in dirfiles
                    For ext = 0 to ubound(ValidExt)-1
                        If instr(right(lcase(dirfile), 4), ValidExt(ext)) > 0 then
                            counter = counter + 1
                            If counter = imgfileloc-1 then
                                prevfile = dirfile.name
                                prevfileloc = counter
                            End if
                            If counter = imgfileloc+1 then
                                nextfile = dirfile.name
                                nextfileloc = counter
                            End if
                        End if
                    Next
                Next
                Set dirfiles = Nothing
                Set dir = Nothing
                result = result & "<table width=""100%"" border=""0"" cellspacing=""3"" cellpadding=""0"">" & vbcrlf
                result = result & "  <tr>" & vbcrlf
                result = result & "    <td width=""50%"" nowrap>"
                If prevfile <> "" then
                    result = result & "<a href=""" & webpath & "?p=" & replace(dirpath, "\", "/") & prevfile & """><<< Previous</a>"
                End if
                result = result & "</td>" & vbcrlf
                result = result & "    <td width=""50%"" nowrap align=""right"">"
                If nextfile <> "" then
                    result = result & "<a href=""" & webpath & "?p=" & replace(dirpath, "\", "/") & nextfile & """>Next >>></a>"
                End if
                result = result & "</td>" & vbcrlf
                result = result & "  </tr>" & vbcrlf
                result = result & "</table>" & vbcrlf
                result = result & "<!-- End STVGallery item display -->" & vbcrlf
            Else
                If err.Number = 0 then
                    result = result & "<br>&nbsp;&nbsp;&nbsp;&nbsp;File not found"
                Else
                    result = result & "<br>&nbsp;&nbsp;&nbsp;&nbsp;" & err.Description
                    err.Clear
                End if
            End if
        Else
            Response.Redirect(webpath)
        End if
    End if
    Set FSO = Nothing
    STVGallery = result
End function
%>
Avatar billede dk_akj Nybegynder
30. juni 2003 - 09:24 #1
I linie 69 kan du bestemme hvor mange kolonner du vil vise.

//akj


<%
Function STVGallery(path)

    Dim ValidExt(4)
    ValidExt(0) = "jpg"
    ValidExt(1) = "gif"
    ValidExt(2) = "png"
    ValidExt(3) = "bmp"
    imgpath = "/pics/"

    On Error Resume Next
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    root = Server.Mappath(".")
    url = Request.ServerVariables("URL")
    webpath = left(url, instrrev(url, "/"))
    If path = "" or right(path, 1) = "/" or right(path, 1) = "\" then
        If instr(path, "/") > 0 then
            path = replace(path, "/", "\")
        End if
        If left(path, 1) <> "\" then
            path = "\" & path
        End if
        If right(path, 1) <> "\" then
            path = path & "\"
        End if
        If instr(path, "..") < 1 then
            uppath = left(replace(path, "\", "/"), instrrev(left(replace(path, "\", "/"), len(path)-1), "/"))
            If uppath = "" then
                uppath = "/"
            End if
            result = vbcrlf & "<!-- Begin STVGallery file list -->" & vbcrlf
            result = result & "<table border=""1"" cellspacing=""3"" cellpadding=""0"">" & vbcrlf
            result = result & "  <tr>" & vbcrlf
            result = result & "    <td width=""18"" align=""center""><a href=""" & webpath & "?p=" & uppath & """><img src=""" & imgpath & "folder_up.gif"" border=""0"" alt=""Tilbage""></a></td>" & vbcrlf
            result = result & "    <td nowrap><a href=""" & webpath & "?p=" & uppath & """>Tilbage</a></td>" & vbcrlf
            result = result & "  </tr>" & vbcrlf
            result = result & "  <tr>" & vbcrlf
            result = result & "    <td colspan=""2"" style=""height: 10px""></td>" & vbcrlf
            result = result & "  </tr>" & vbcrlf
            If FSO.FolderExists(root & path) then
                Set dir = FSO.GetFolder(root & path)
                Set subdirs = dir.SubFolders
                For each subdir in subdirs
                    If err.Number = 0 then
                        result = result & "  <tr>" & vbcrlf
                        result = result & "    <td align=""center""><a href=""" & webpath & "?p=" & replace(path, "\", "/") & subdir.name & "/""><img src=""" & imgpath & "folder.gif"" border=""0"" alt=""Folder""></a></td>" & vbcrlf & "    <td nowrap><a href=""" & webpath & "?p=" & replace(path, "\", "/") & subdir.name & "/"">" & subdir.name & "</a></td>" & vbcrlf
                        result = result & "  </tr>" & vbcrlf
                    Else
                        result = result & "  <tr>" & vbcrlf
                        result = result & "    <td></td><td>" & err.Description & "</td>" & vbcrlf
                        result = result & "  </tr>" & vbcrlf
                        err.Clear
                    End if
                Next
                Set subdirs = Nothing
                Set dirfiles = dir.Files
               
                result = result & "<tr>" & vbcrlf           
                i = 0   
           
                For each dirfile in dirfiles
                    For ext = 0 to ubound(ValidExt)-1
                        If instr(right(lcase(dirfile), 4), ValidExt(ext)) > 0 then
                            i = I + 1
                           
                            if i > 5  then  ' tallet angiver hvor mange kolonner billederne skal vises i
                                result = result & "</tr><tr>" & vbcrlf
                                i = 1
                            end if

                            result = result & "    <td align=""center""><a href=""" & webpath & "?p=" & replace(path, "\", "/") & dirfile.name & """><img src=""" & imgpath & "file.gif"" border=""0"" alt=""File""></a></td>" & vbcrlf & "    <td nowrap><a href=""" & webpath & "?p=" & replace(path, "\", "/") & dirfile.name & """>" & dirfile.name & "</a></td>" & vbcrlf
                           
                        End if
                    Next
                Next
   
                result = result & "</tr>" & vbcrlf                               
               
                Set dirfiles = Nothing
                Set dir = Nothing
            Else
                result = result & "  <tr>" & vbcrlf
                result = result & "    <td></td>" & vbcrlf
                result = result & "    <td nowrap>Path not found</td>" & vbcrlf
                result = result & "  </tr>" & vbcrlf
            End if
            result = result & "</table>" & vbcrlf
            result = result & "<!-- End STVGallery file list -->" & vbcrlf
        Else
            Response.Redirect(webpath)
        End if
    Else
        If instr(path, "/") > 0 then
            path = replace(path, "/", "\")
        End if
        If left(path, 1) <> "\" then
            path = "\" & path
        End if
        If instr(path, "..") < 1 then
            uppath = left(replace(path, "\", "/"), instrrev(left(replace(path, "\", "/"), len(path)-1), "/"))
            result = vbcrlf & "<!-- Begin STVGallery item display -->" & vbcrlf
            result = result & "<table border=""0"" cellspacing=""3"" cellpadding=""0"">" & vbcrlf
            result = result & "  <tr>" & vbcrlf
            result = result & "    <td width=""18"" align=""center""><a href=""" & webpath & "?p=" & uppath & """><img src=""" & imgpath & "folder_up.gif"" border=""0"" alt=""Up""></a></td>" & vbcrlf
            result = result & "    <td nowrap><a href=""" & webpath & "?p=" & uppath & """>Tilbage</a></td>" & vbcrlf
            result = result & "  </tr>" & vbcrlf
            result = result & "</table>" & vbcrlf
            If uppath = "" then
                uppath = "/"
            End if
            If FSO.FileExists(root & path) then
                Set imgfile = FSO.GetFile(root & path)
                imgname = imgfile.Name
                result = result & "<p align=""center""><a href=""" & webpath & "?p=" & replace(path, "\", "/") & """>" & imgname & "</a><br><br><img src=""" & webpath & right(replace(path, "\", "/"), len(path)-1) & """ alt=""" & imgname & """></p>" & vbcrlf
                Set imgfile = Nothing
                dirpath = left(path, len(path)-len(imgname))
                Set dir = FSO.GetFolder(root & dirpath)
                Set dirfiles = dir.Files
                counter = 0
                For each dirfile in dirfiles
                    For ext = 0 to ubound(ValidExt)-1
                        If instr(right(lcase(dirfile), 4), ValidExt(ext)) > 0 then
                            counter = counter + 1
                            If instr(dirfile, imgname) > 0 then
                                imgfileloc = counter
                            End if
                        End if
                    Next
                Next
                counter = 0
                For each dirfile in dirfiles
                    For ext = 0 to ubound(ValidExt)-1
                        If instr(right(lcase(dirfile), 4), ValidExt(ext)) > 0 then
                            counter = counter + 1
                            If counter = imgfileloc-1 then
                                prevfile = dirfile.name
                                prevfileloc = counter
                            End if
                            If counter = imgfileloc+1 then
                                nextfile = dirfile.name
                                nextfileloc = counter
                            End if
                        End if
                    Next
                Next
                Set dirfiles = Nothing
                Set dir = Nothing
                result = result & "<table width=""100%"" border=""0"" cellspacing=""3"" cellpadding=""0"">" & vbcrlf
                result = result & "  <tr>" & vbcrlf
                result = result & "    <td width=""50%"" nowrap>"
                If prevfile <> "" then
                    result = result & "<a href=""" & webpath & "?p=" & replace(dirpath, "\", "/") & prevfile & """><<< Previous</a>"
                End if
                result = result & "</td>" & vbcrlf
                result = result & "    <td width=""50%"" nowrap align=""right"">"
                If nextfile <> "" then
                    result = result & "<a href=""" & webpath & "?p=" & replace(dirpath, "\", "/") & nextfile & """>Next >>></a>"
                End if
                result = result & "</td>" & vbcrlf
                result = result & "  </tr>" & vbcrlf
                result = result & "</table>" & vbcrlf
                result = result & "<!-- End STVGallery item display -->" & vbcrlf
            Else
                If err.Number = 0 then
                    result = result & "<br>&nbsp;&nbsp;&nbsp;&nbsp;File not found"
                Else
                    result = result & "<br>&nbsp;&nbsp;&nbsp;&nbsp;" & err.Description
                    err.Clear
                End if
            End if
        Else
            Response.Redirect(webpath)
        End if
    End if
    Set FSO = Nothing
    STVGallery = result
End function
%>
Avatar billede bjuhl Nybegynder
30. juni 2003 - 19:25 #2
Mange Tak for hjælpen.

200 point til dig.
Avatar billede dk_akj Nybegynder
30. juni 2003 - 21:24 #3
Selvtak.

//akj
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester