IF exist /w FSO

E

EQNish

IS there a way I can do an If exist to determin if a graphic is displayed?

something like this;


<p align="center">

if file exist "fileone.jpg"
<img border="0" src="fileone.jpg">
if File exist "filetwo.jpg"
<img border="0" src="fileone.jpg">
</p>


What I am trying to do is post JPGs from a folder structure, the files may
or maynot be there, but I don't want to have the blank picture reference to
be displayed as if I where to just hard code the graphics in the Html!
 
A

Anthony Jones

EQNish said:
IS there a way I can do an If exist to determin if a graphic is displayed?

something like this;


<p align="center">

if file exist "fileone.jpg"
<img border="0" src="fileone.jpg">
if File exist "filetwo.jpg"
<img border="0" src="fileone.jpg">
</p>


What I am trying to do is post JPGs from a folder structure, the files may
or maynot be there, but I don't want to have the blank picture reference to
be displayed as if I where to just hard code the graphics in the Html!

Try this (warning air code):-

<%

Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

Dim fileNames
fileNames= Array("fileone.jpg", "filetwo.jpg") 'Note these are URL paths

%>


<p align="center">
<%

Dim fileName
For Each fileName in fileNames
If fso.FileExists(Server.MapPath(fileName)) Then
%>
<img border="0" src="<%=fileName%>" />
<%
End If
Next
%>
</p>
 
E

Evertjan.

Anthony Jones wrote on 16 mei 2008 in
microsoft.public.inetserver.asp.general:
Try this (warning air code):-

<%

Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

Dim fileNames
fileNames= Array("fileone.jpg", "filetwo.jpg") 'Note these are URL
paths

%>


<p align="center">
<%

Dim fileName
For Each fileName in fileNames
If fso.FileExists(Server.MapPath(fileName)) Then
%>
<img border="0" src="<%=fileName%>" />
<%
End If
Next
%>
</p>

Or you can send a default I'm-sorry-image by dedicated 404.asp, having:

qstr = lcase(Request.ServerVariables("QUERY_STRING"))
if right(qstr,4)=".jpg" or right(qstr,4)=".gif" then
response.redirect "/special/404.jpg"
end if

[make sure /special/404.jpg exists]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top