Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image gallery code 1

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
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 \
Code:
<HTML>
<HEAD>
</HEAD>

<%
if request(&quot;gallery&quot;) <> &quot;&quot; and not isempty(request(&quot;gallery&quot;)) then
	dir = request(&quot;gallery&quot;)
	%>
	<FRAMESET frameborder=0 rows=&quot;80%,20%&quot;>
	<FRAME src=&quot;viewpic.asp?gallery=<%=dir%>&quot;  NAME=&quot;Top Frame&quot;  scrolling=YES>
	<FRAME src=&quot;menu.asp?gallery=<%=dir%>&quot;  NAME=&quot;Bottom Frame&quot; scrolling=YES>

</FRAMESET>
<%
else
%>
<Body>
<center><b> Gallery not found, please chose from the following </b></center>
<%
	
Set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Path = Request.ServerVariables(&quot;PATH_TRANSLATED&quot;)
rt = InstrRev(Path,&quot;\&quot;)
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) <> &quot;_&quot; then
			Response.write &quot;<br><a href=&quot;&quot;index.asp?gallery=&quot;& Server.UrlEncode(fol.name) &&quot;&quot;&quot;>&quot; & fol.name & &quot;</a>&quot;
		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=&quot;#B5BED6&quot; text=&quot;#BFF2EF&quot; link=&quot;#FDE0E0&quot; vlink=&quot;#C1C1A0&quot;>

<table border=&quot;0&quot; cellspacing=&quot;2&quot; cellpadding=&quot;0&quot;>
<tr>
<%
Set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Path = Request.ServerVariables(&quot;PATH_TRANSLATED&quot;)
dir = Request(&quot;gallery&quot;)
rt = InstrRev(Path,&quot;\&quot;)
Path = Mid(Path, 1, rt) & dir & &quot;\thumbnails\&quot;
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) = &quot;jpg&quot; or LCase(FileExt) = &quot;gif&quot; then
	%>
		<td valign=top> &nbsp; 
			<a href=&quot;viewpic.asp?gallery=<%=Server.urlEncode(trim(dir))%>&wcpic=<%=Server.URLEncode(fsFile.name)%>&quot; target=&quot;Top Frame&quot;><img src=&quot;<%=dir%>/thumbnails/<%=fsFile.name%>&quot; border=&quot;0&quot; align=&quot;BOTTOM&quot;></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=&quot;darkgray&quot;  text=&quot;#000000&quot;  link=&quot;#FF0000&quot;  vlink=&quot;#CCCC99&quot; <%'if not IsIE then Response.Write bodyload %>>
<%
if Request(&quot;wcpic&quot;) = &quot;&quot; or IsEmpty(Request(&quot;wcpic&quot;)) then
	dir = Request(&quot;gallery&quot;)
	Set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
	Path = Request.ServerVariables(&quot;PATH_TRANSLATED&quot;)
	rt = InstrRev(Path,&quot;\&quot;)
	Path = Mid(Path, 1, rt) & dir & &quot;\thumbnails\&quot;
	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) = &quot;jpg&quot; or LCase(FileExt) = &quot;gif&quot; then
				wcpic = fsFile.name	
			end if
			exit for
		next
	end if

else
	dir =  request(&quot;gallery&quot;)
	wcpic = Request(&quot;wcpic&quot;)
end if
%>

<table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;2&quot; width=&quot;100%&quot; bgcolor=&quot;lightgrey&quot;>
<tr>
	<td><font size=&quot;3&quot; face=&quot;Courier New&quot;> <%=wcpic%> </font>
	</td>
</tr>
</table>

<center><img src=&quot;./<%=dir%>/images/<%=wcpic%>&quot; border=&quot;0&quot; alt=&quot;<%=wcpic%>&quot;></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}
kblogo.jpg
 
Well somebody liked it :) Karl Blessing aka kb244{fastHACK}
kblogo.jpg
 
Amazing, I was about to attempt this myself, but now I will just steal you code. Thanks

G -GTM Solutions, Home of USITE-
-=
 
Very Good solution !

Thank you for having saved me a lot of wasting time !

I'm almost new to ASP and, as usual, I've my de-mental
problems in &quot;automatization&quot; of pages ...

It seems my brain get looping in a black-hole !

MAH, let's get COFFEE and follow on !
Maybe I'll succeed in contribute something usefull also for you.

THANKS.

SWApiccolo.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top