Karl Blessing
Programmer
I wrote this for my site a while back.
at first I was making Photoshop 6 batch generate a website based on a couple images, And that went all fine and dandy. But I didnt like how I had to regenerate, or have several pages everytime I wanted to upload new pics.
so... I thought of a way to have it dynamic, where all you would have to do is just add a folder, plop in the images, plop in the thumbnails and be on your way.
First I'll show the layout, and the code, then I'll explain how to link people to the images.
Basic layout
/Rootgallery folder
/AGalleryFolder
/images
/thumbnails
.index.asp
.menu.asp
.viewpic.asp
only 3 asp files, and however many gallery subfolders you need.
The thumbnails and images, must be the exact same filename the only difference is the thumbnails are going to be smaller of course.
/ index.asp \
in index.asp you will notice it does one of two things. One, if a gallery name was given (the folder name of the gallery) then it goes ahead and calls menu and viewpic to display that gallery. Otherwise it will give you a list of the subdirectories names, as galleries to chose from.
/ menu.asp \
With menu.asp , it will basically go through and look through the list of thumbnails under the subdirectory for the gallery you given it. It will then also link to the images passing it to viewpic, which consist of the same name as the thumbnails, only slightly different path.
/ viewpic.asp \
In viewpic.asp , this is where it actually takes the image that was submited by the menu, and displays it. If no image was passed, it will display the first image it finds in the /image folder under the galleryname subdirectory
Sure there could be enhancments made, but I figured this was good enough for me, in the future I might have paging for the menu if needed.
Hope you enjoy this. Karl Blessing aka kb244{fastHACK}
at first I was making Photoshop 6 batch generate a website based on a couple images, And that went all fine and dandy. But I didnt like how I had to regenerate, or have several pages everytime I wanted to upload new pics.
so... I thought of a way to have it dynamic, where all you would have to do is just add a folder, plop in the images, plop in the thumbnails and be on your way.
First I'll show the layout, and the code, then I'll explain how to link people to the images.
Basic layout
/Rootgallery folder
/AGalleryFolder
/images
/thumbnails
.index.asp
.menu.asp
.viewpic.asp
only 3 asp files, and however many gallery subfolders you need.
The thumbnails and images, must be the exact same filename the only difference is the thumbnails are going to be smaller of course.
/ index.asp \
Code:
<HTML>
<HEAD>
</HEAD>
<%
if request("gallery") <> "" and not isempty(request("gallery")) then
dir = request("gallery")
%>
<FRAMESET frameborder=0 rows="80%,20%">
<FRAME src="viewpic.asp?gallery=<%=dir%>" NAME="Top Frame" scrolling=YES>
<FRAME src="menu.asp?gallery=<%=dir%>" NAME="Bottom Frame" scrolling=YES>
</FRAMESET>
<%
else
%>
<Body>
<center><b> Gallery not found, please chose from the following </b></center>
<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Path = Request.ServerVariables("PATH_TRANSLATED")
rt = InstrRev(Path,"\")
Path = Mid(Path, 1, rt)
if fs.FolderExists(Path) then
Set fsFol = fs.GetFolder(Path)
Set fsSub = fsFol.SubFolders
For Each fol in fsSub
if left(fol.name, 1) <> "_" then
Response.write "<br><a href=""index.asp?gallery="& Server.UrlEncode(fol.name) &""">" & fol.name & "</a>"
end if
next
end if
%>
</Body>
<%
end if
%>
</HTML>
in index.asp you will notice it does one of two things. One, if a gallery name was given (the folder name of the gallery) then it goes ahead and calls menu and viewpic to display that gallery. Otherwise it will give you a list of the subdirectories names, as galleries to chose from.
/ menu.asp \
Code:
<%@ Language=VBScript %>
<html>
<head>
</head>
<body bgcolor="#B5BED6" text="#BFF2EF" link="#FDE0E0" vlink="#C1C1A0">
<table border="0" cellspacing="2" cellpadding="0">
<tr>
<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Path = Request.ServerVariables("PATH_TRANSLATED")
dir = Request("gallery")
rt = InstrRev(Path,"\")
Path = Mid(Path, 1, rt) & dir & "\thumbnails\"
Dim Temp, GetVersion
if fs.FolderExists(Path) then
Set fsFol = fs.GetFolder(Path)
Set fsFiles = fsFol.Files
For each fsFile in fsFiles
ObjectPath = fsFile.path
FileExt = fs.GetExtensionName(ObjectPath)
If LCase(FileExt) = "jpg" or LCase(FileExt) = "gif" then
%>
<td valign=top>
<a href="viewpic.asp?gallery=<%=Server.urlEncode(trim(dir))%>&wcpic=<%=Server.URLEncode(fsFile.name)%>" target="Top Frame"><img src="<%=dir%>/thumbnails/<%=fsFile.name%>" border="0" align="BOTTOM"></a>
</td>
<%
end if
next
Else
%>
<Font color=Red size=+2> Path does not exist or is not ready<BR>Contact WebMaster.</Font></BR>
<%
end if
%>
</tr>
</table>
</body>
</html>
With menu.asp , it will basically go through and look through the list of thumbnails under the subdirectory for the gallery you given it. It will then also link to the images passing it to viewpic, which consist of the same name as the thumbnails, only slightly different path.
/ viewpic.asp \
Code:
<%@ Language=VBScript %>
<HTML>
<BODY bgcolor="darkgray" text="#000000" link="#FF0000" vlink="#CCCC99" <%'if not IsIE then Response.Write bodyload %>>
<%
if Request("wcpic") = "" or IsEmpty(Request("wcpic")) then
dir = Request("gallery")
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Path = Request.ServerVariables("PATH_TRANSLATED")
rt = InstrRev(Path,"\")
Path = Mid(Path, 1, rt) & dir & "\thumbnails\"
if fs.FolderExists(Path) then
Set fsFol = fs.GetFolder(Path)
Set fsFiles = fsFol.Files
For each fsFile in fsFiles
ObjectPath = fsFile.path
FileExt = fs.GetExtensionName(ObjectPath)
If LCase(FileExt) = "jpg" or LCase(FileExt) = "gif" then
wcpic = fsFile.name
end if
exit for
next
end if
else
dir = request("gallery")
wcpic = Request("wcpic")
end if
%>
<table border="0" cellpadding="5" cellspacing="2" width="100%" bgcolor="lightgrey">
<tr>
<td><font size="3" face="Courier New"> <%=wcpic%> </font>
</td>
</tr>
</table>
<center><img src="./<%=dir%>/images/<%=wcpic%>" border="0" alt="<%=wcpic%>"></center>
</BODY>
</HTML>
In viewpic.asp , this is where it actually takes the image that was submited by the menu, and displays it. If no image was passed, it will display the first image it finds in the /image folder under the galleryname subdirectory
Sure there could be enhancments made, but I figured this was good enough for me, in the future I might have paging for the menu if needed.
Hope you enjoy this. Karl Blessing aka kb244{fastHACK}