Click here to Skip to main content
15,867,870 members
Articles / Web Development / HTML
Article

Simple Image Gallery with ASP

Rate me:
Please Sign up or sign in to vote.
2.55/5 (9 votes)
29 Oct 20041 min read 75.6K   1   26   1
A simple image gallery with captions using ASP.

ASP Image Gallery

View a demo online

Download Source Files with Demo Pictures

A simple 1 file asp based image gallery with captions. To use simply place the asp file in a folder with other folders that contain images. Within each folder you then place a text file called captions.txt, with one caption on each line of the text file to correspond with each image (sorted by image name). When displayed on the web, the caption will be displayed above each picture. This relies on the fils system object. Most web hosts support this, but if you have trouble or receive errors, you may want to contact your ISP and ask if they support the use of the file system object.

The script is made up of 2 parts.

First part is to read the folders and display a link with the folder name. We loop create a file system object then loop through each folder found and also display the size in MB contained in each folder. Each folder name is then a link to display the images and captions.
asp image gallery

The second part of the file will loop through all JPG and GIF images, then open the captions.txt file and also grab each line and then "match-up" the 2 groupd of lists to write the caption at the top of each image, each image is also clickable to display by itself for printing.
captions file

 

<P><CODE><%
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

qfolder = request.querystring("f")
if qfolder = "" then
folderspec = server.mappath(".")
Set filesys = CreateObject("Scripting.FileSystemObject") 
Set demofolder = filesys.GetFolder(folderspec) 
Set folcoll = demofolder.SubFolders
For Each subfol in folcoll
folsize = left((subfol.size/1000000), 3)
folist = folist & "<A href='?f=" & subfol.name & "'></STRONG"> " & subfol.Name & " </A><small> (" & folsize & " MB)</small>" & vbcrlf
folist = folist & "
" 
Next
set filesys = nothing
Response.Write folist

else

filepath = server.mappath(".") & "\" & qfolder
captionfile = filepath & "\captions.txt"
Set filesys = CreateObject("Scripting.FileSystemObject")
Dim SomeArray()
'caption part
If filesys.FileExists(captionfile) then
set file = filesys.GetFile(captionfile)
Set TextStream = file.OpenAsTextStream(ForReading,TristateUseDefault)
captioncount = 0
Do While Not TextStream.AtEndOfStream
Line = TextStream.readline
ReDim Preserve SomeArray(captioncount)
SomeArray(captioncount) = line
'response.write captioncount & " " & somearray(captioncount) & "
"
captioncount = captioncount + 1
'Response.write Line
Loop
textStream.close
end if
'folder part
Set demofolder = filesys.GetFolder(filepath) 
Set filecoll = demofolder.Files
filecount = 0
For Each file in filecoll
Ext = UCase(Right(File.Path, 3)) 
If Ext = "JPG" OR Ext = "GIF" Then
on error resume next
data = SomeArray(filecount)
on error goto 0
hrefpath = qfolder & "/" & file.name
imagepath = "^__STRONG>" & data & "
<A title="free image gallery" href='"%20&%20hrefpath%20&%20"'><img src='" & hrefpath & "' border='1' title='" & data & "'></A>
"
filist = filist & imagepath & vbcrlf
filist = filist & "
"
filecount = filecount + 1
data = ""
end if
Next
set filesys = Nothing
filist = filist & "
<small><a href='http://www.allscoop.com/' target='_blank'>free image gallery</A></small>"
%>

<h3><A title="up one level"</A>
 <%=qfolder%></h3>

</P><P><%=filist%></P>

<% end if %>
</CODE>

That is it, very simple and easy to use. Certainly not full of features, but if you just need to quickly get some pictures up with captions...it's pretty easy. Hope you enjoy it!

View a demo online

Download Source Files with Demo Pictures

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
Live in Michigan, USA

Comments and Discussions

 
Generalthanks ! Pin
haim9626-Dec-06 5:44
haim9626-Dec-06 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.