29. december 2003 - 00:55Der er
27 kommentarer og 1 løsning
hente billeder fra mappe > tabel
Skal bruge et script der kan tage alle *.jpg billeder fra en mappe, og smide dem ind i en tabel, som på: www.t3ch.dk/bin/pic/ og skriver billedets titel i en celle under billedet.
Ikke thumbnail, da billederne ikke skal linke til noget.
Jeg har dette du kan prøve at bruge til det formål. Du kan bestemme hvor mange billeder der skal vise pr række med variablen maxImgPrRow = 4
Samt rette stien til med variablen sti, lige nu skal ASP filen ligge sammen med billederne. sti = "./"
Så prøv:
<html> <body> <% sti = "./" Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) Set Folder = fs.GetFolder( Server.Mappath(sti) ) %> <TABLE WIDTH="100%"> <% imgPrRow = 0 maxImgPrRow = 4 For Each file in Folder.Files If Right(file.Name,4) = ".jpg" Then if imgPrRow = 0 then Response.Write "<tr>" %> <td align="center"><img src="<%=sti%><%=file.Name%>" border="0" alt="<%=file.Name%>"> <br><%=file.Name%> </td> <% imgPrRow = imgPrRow + 1 if imgPrRow = maxImgPrRow then Response.Write "</tr>" imgPrRow = 0 end if End If Next if imgPrRow > 0 then Response.Write "</tr>" %> </table> </body> </html>
FSO kan ikke sorteere filerne så skal man først ligge dem ind i enten et array eller recordset for sortere navne i arrayet/recordset for så at skrive det ud.
<% sti = "./" Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) Set Folder = fs.GetFolder( Server.Mappath(sti) )
filList = "" For Each file in Folder.Files If Right(file.Name,4) = ".jpg" Then filList = filList & "," & file.Name end if next if filList <> "" then filList = Mid(filList,2) filArr = Split(filList,",") filArr = Sorter(filArr)
%>
<TABLE WIDTH="100%"> <% imgPrRow = 0 maxImgPrRow = 4 For i = lbound(filArr) to ubound(filArr) if imgPrRow = 0 then Response.Write "<tr>" %> <td align="center"><img src="<%=sti%><%=filArr(i)%>" border="0" alt="<%=filArr(i)%>"> <br><%=filArr(i)%> </td> <% imgPrRow = imgPrRow + 1 if imgPrRow = maxImgPrRow then Response.Write "</tr>" imgPrRow = 0 end if Next if imgPrRow > 0 then Response.Write "</tr>" %> </table> </body> </html>
<% Function Sorter(ByVal tabel) Dim blnContinue, i, varFirst, varSecond blnContinue = True Do Until blnContinue = False blnContinue = False For i = 0 to UBound(tabel) If i = UBound(tabel) Then Exit For Arr = Split(tabel(i),".") tmp1 = arr(0) Arr = Split(tabel(i+1),".") tmp2 = arr(0) If tmp1 > tmp2 Then varFirst = tabel(i) varSecond = tabel(i+1) tabel(i) = varSecond tabel(i+1) = varFirst blnContinue = True End If Next Loop Sorter = tabel End Function %>
<% Function Sorter(ByVal tabel) Dim blnContinue, i, varFirst, varSecond blnContinue = True Do Until blnContinue = False blnContinue = False For i = 0 to UBound(tabel) If i = UBound(tabel) Then Exit For Arr = Split(tabel(i),".") tmp1 = arr(0) if isnumeric(tmp1) then tmp1 = Int(tmp1) Arr = Split(tabel(i+1),".") tmp2 = arr(0) if isnumeric(tmp2) then tmp2 = Int(tmp2) If tmp1 > tmp2 Then varFirst = tabel(i) varSecond = tabel(i+1) tabel(i) = varSecond tabel(i+1) = varFirst blnContinue = True End If Next Loop Sorter = tabel End Function %>
så skal du hvade bygget paging in på og der så letter da du har det med arrayet...
<html> <body>
<% sti = "./" Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) Set Folder = fs.GetFolder( Server.Mappath(sti) )
filList = "" For Each file in Folder.Files If Right(file.Name,4) = ".jpg" Then filList = filList & "," & file.Name end if next if filList <> "" then filList = Mid(filList,2) filArr = Split(filList,",") filArr = Sorter(filArr)
%>
<TABLE WIDTH="100%"> <% start = Request.Querystring("start") if start = "" then start = 0 antalBillederPrSide = 40 imgPrRow = 0 maxImgPrRow = 4 Antalsider = int(ubound(filArr) / antalBillederPrSide) for i = start to (start + antalBillederPrSide-1) if not i > ubound(filArr) then
if imgPrRow = 0 then Response.Write "<tr>" %> <td align="center"><img src="<%=sti%><%=filArr(i)%>" border="0" alt="<%=filArr(i)%>"> <br><%=filArr(i)%> </td> <% imgPrRow = imgPrRow + 1 if imgPrRow = maxImgPrRow then Response.Write "</tr>" imgPrRow = 0 end if else nesteside = 1 end if Next if imgPrRow > 0 then Response.Write "</tr>" %> </table> <% if start <> 0 then response.write "<a href=""?start=" & (start - antalBillederPrSide) & """>Forrige</a>" end if response.write(" ") if nesteside <> 1 then response.write "<a href=""?start=" & (start + antalBillederPrSide) & """>Næste</a>" end if %> </body> </html>
hedder billeder 3D1.jpg, etc... bliver de sorteret således:
3D1.jpg 3D2.jpg etc..
hedder billeder derimod B1.jpg, etc.. bliver de sorteret på denne måde: B1.jpg B10.jpg etc..
why?
Kode:
<% sti = "./" Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) Set Folder = fs.GetFolder( Server.Mappath(sti) )
filList = "" For Each file in Folder.Files If Right(file.Name,4) = ".jpg" Then filList = filList & "," & file.Name end if next if filList <> "" then filList = Mid(filList,2) filArr = Split(filList,",") filArr = Sorter(filArr)
%>
</p> </font> <font size="1" color="#000000">
<TABLE WIDTH="100%"> <% start = Request.Querystring("start") if start = "" then start = 0 antalBillederPrSide = 48 imgPrRow = 0 maxImgPrRow = 6 Antalsider = int(ubound(filArr) / antalBillederPrSide) for i = start to (start + antalBillederPrSide-1) if not i > ubound(filArr) then
if imgPrRow = 0 then Response.Write "<tr>" %> <td align="center"><img src="<%=sti%><%=filArr(i)%>" border="0" alt="<%=filArr(i)%>"> <%=filArr(i)%> </td> <% imgPrRow = imgPrRow + 1 if imgPrRow = maxImgPrRow then Response.Write "</tr>" imgPrRow = 0 end if else nesteside = 1 end if Next if imgPrRow > 0 then Response.Write "</tr>" %> </table> </font> <br> <center>
<% if start <> 0 then response.write "<a target='_self' href=""?start=" & (start - antalBillederPrSide) & """><b><- Forrige</b></a> |" end if response.write(" ") if nesteside <> 1 then response.write "<a target='_self' href=""?start=" & (start + antalBillederPrSide) & """><b>Næste -></b></a><br>" end if for i = 0 to Antalsider response.write "<a target='_self' href=""?start=" & ((i)*antalBillederPrSide) & """><b>"&(i+1)&"</b></a> " next %> </center>
<% Function Sorter(ByVal tabel) Dim blnContinue, i, varFirst, varSecond blnContinue = True Do Until blnContinue = False blnContinue = False For i = 0 to UBound(tabel) If i = UBound(tabel) Then Exit For Arr = Split(tabel(i),".") tmp1 = arr(0) if isnumeric(tmp1) then tmp1 = Int(tmp1) Arr = Split(tabel(i+1),".") tmp2 = arr(0) if isnumeric(tmp2) then tmp2 = Int(tmp2) If tmp1 > tmp2 Then varFirst = tabel(i) varSecond = tabel(i+1) tabel(i) = varSecond tabel(i+1) = varFirst blnContinue = True End If Next Loop Sorter = tabel End Function %> <br>
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.