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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IMG link "sprucer" from RS

Status
Not open for further replies.

CyrusAyers

Programmer
Feb 4, 2004
25
US
Gurus,
It would be nice if my code could check the validity of a image src coming from a RS instead of just not showing an X on the blank ones - keeping nasty X's from onlookers in the case of a typeo. Is there a better alternative?
Code:
<%if rs("imagebox")<>"" then
strImage = rs("imagebox")	%>
<img src="/pictures/<%=strImage%>" alt="<%=strImage%>" align="right">
<%end if%>
Thanks for any advice!
 
Check for the file existing on the drive using the FSO (FileExists(path)) before writing the <img src...>



Chris.

Indifference will be the downfall of mankind, but who cares?
 
You need to get the image from external source i dont knw if this will work. But this way should work if you have image stored binary in database. There is an example of uploading and extracting the image from database.

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Interesting examples and suggestions! The following dosent generate an error to speak of, but the picture isnt showing... (all the other fields are coming up)

Code:
<%
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
imgvar = rs("imagebox")
If oFS.FileExists("/RecipePictures/" & imgvar) then%>
<img src="/recipepictures/<%=imgvar%>" alt="<%=imgvar%>" align="right">
<%end if%>
 
In order for your image to be displayed corectly you would need to change the content type of the data to image/jpeg for example if you stored an jpeg in database.

But since you cannot change your content type in the middle of your ASP you would need that the src data for an image to be from andother ASP page that will print out the right content type.
Code:
...
<img src="getImage.asp?id=10">


getImage.asp

<%
'get your data from database
Response.ContentType=rs("contenttype")
Response.BinaryWrite rs("imagedata")
%>




________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
FileExists() takes a physical path not a relative one so it would have to be,

Code:
 oFS.FileExists(server.MapPath("\RecipePictures\" & imgvar))




Chris.

Indifference will be the downfall of mankind, but who cares?
 
You shouold probably add an else case to that if check also, maybe create a generic image that says "Image Not Available" and in your else put that one out.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top