Click to See Complete Forum and Search --> : Asp image link creation
bahama llama
03-05-2003, 04:02 PM
I am trying to make an asp script that would create an image gallery of ten images with links to larger pics. the thumbnails would be kept in a folder in the same directory called thumbs and the larger ones in a folder called images. I want to name the images consecutively, and numerically, ie. 1.jpg, 2.jpg, 3.jpg.
I could create the pages by hand but I figure that one script should be able to handle it for all the pages. I also would not like to use a database if possible, but would be willing too if necessary.
I was thinking of using an array and figure that the naming convention would help.
If anyone has any ideas or links to a good tutorial to use it would be appreciated. Don :confused:
chubtub
03-05-2003, 04:46 PM
<%
'This would best be run in the folder that the images(thumbs are in)
'the large images would be in a subfolder called "images"
'remember to change the file type to .jpg I have .gif just for testing
'the files type needs to be changed in two areas
BuildLinks = True
ImageNumber = 1
'Path to images
MainPath = "c:\websites\test\"
Do while BuildLinks = True
'Conplete path needed starting from c:
FullPath = MainPath & cStr(ImageNumber) & ".gif"
'debugging to check actual path
'response.write FullPath & "<br>"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
If (fs.FileExists(FullPath))=true Then
DisplayString = DisplayString & "<A Href='/images/" & ImageNumber & ".gif & '><img src=" & ImageNumber & ".gif alt=''></a>"
Else
Buildlinks = False
End If
set fs=nothing
ImageNumber = ImageNumber + 1
Loop
Response.write DisplayString
%>
If you are good with tables then you can add the table code to the display string, did not have time to do it. Or just add in the string to break them up. I will assume that you can figure something to format these.
The filesystemobject that I use is I believe in all IIS installs, so you should be good.:)
You might have to move some of this around if you cut and past the formatting of the forms has added some returns in the code. Like building the displaystring should only be one line not two.
bahama llama
03-05-2003, 05:37 PM
Thanks for the quick reply. I'm going to give it a shot and repost on the results.
here is what I was trying. It's real simple for troubleshooting(ie.not tables):
<HTML>
<BODY>
<%
dim i
for i=1 to 3
response.write("<IMG SRC="thumbs/"& i &".jpeg">")
next
%>
</BODY>
</HTML>
If I write it like this it tells me I have a compilation error and points to the first " after SRC= .
If I replace it with just ' as is sometimes required I think in JavaScript, it displays the page with three image holders but no images. When I check the source the ' stays.
Is there someway that I could make this work?
Don.:t
chubtub
03-05-2003, 05:50 PM
Try this out it might work to replace your response.write. Most browsers can get by without quotes in alot of the values, which makes it easier to code. You just need spaces for most inbetween attributes.
The browser thinks that you are ending the string there with the second quote mark.
This should do it.
response.write "<IMG SRC=thumbs/" & i & ".jpeg>"
PS in the code I wrote above you have to change the gif to jpeg in 3 places sorry. With that code all you have to do is drop in the numbered picts and it will find them and diplay automatically, no need to change code.:)
bahama llama
03-05-2003, 05:51 PM
I tried the script but no luck, just the http header, I put it in html tags and that's all I get back. I know i have the permission set right to run scripts from this dir but no go. I can't quite figure it out. :confused: Don.
kpm547
03-05-2003, 05:57 PM
to solve your compilation error, use this:
response.write("<IMG SRC='thumbs/" & i &".jpeg'>")
quotes that are required for the html in your asp code need to be single quotes ' so that the asp doesn't get confused.
I see another problem that will occur with chubtub's script. The last line in his script:
Response.write DisplayString
needs to be inside the Do/Loop otherwise it will only show the last picture.
chubtub
03-05-2003, 06:02 PM
With the code above you should not need any HTML tags just from the <% to the other %>, and named .asp
I am assuming that this web site does have execute rights on it for scripts, set in IIS.
You can try uncommenting out the
'response.write FullPath & "<br>"
to
response.write FullPath & "<br>"
it might be that the path is not correct. I had to redo mine twice to get it right, this would show you the full path that the fies should be in when you run it.
chubtub
03-05-2003, 06:05 PM
Should display them all since it is -
DisplayString = DisplayString &
I ran the code on my server with 4 images, worked good for me :)
bahama llama
03-05-2003, 06:18 PM
Thanks Kpm547 that did the trick. This will work better since there will be a large number of directories and I would like one script to dynamically create all the pages. I really appreciate all of you help. I will repost if I have any other problems, or once I get a fully functional prototype up and running. Don.:t :D
Here's the version I made for links. Now I just have to include this script in all the default.asp pages and I should be set.
<HTML>
<BODY>
<%
dim i
for i=1 to 3
response.write("<A HREF=pics/"& i &".jpg><IMG SRC=thumbs/"& i &".jpg></A>")
next
%>
</BODY>
</HTML>
It seems like any programming problem, there usually are several solutions. Thanks again for everyone's help.
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.