#1
  1. No Profile Picture
    MySQL Newbie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Melbourne, Australia
    Posts
    9
    Rep Power
    0

    Question Hide missing images???


    Is there a way I can test if an image file exists before displaying it?

    I have a database that has an image field in it that users enter a filename into. Is there a way for me to check using an "if" statement that the file is actually on the drive before displaying it? ie:

    <%okimage=(rsFile.Fields.Item("image").Value)
    If okimage='actually on the drive' then%>
    <img src='(rsFile.Fields.Item("image").Value)'>
    <%else%>
    <img src='noimage.jpg'>
    <%end if%>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    138
    Rep Power
    12
    Code:
    <%
    Dim objFs
    Set objFs = Server.CreateObject("Scripting.FileSystemObject")
    
    IF objFs.FileExists(Server.Mappath(rsFile.Fields.Item("image").Value) ) Then
    %>
    <img src='(rsFile.Fields.Item("image").Value)'>
    <%else%>
    <img src='noimage.jpg'>
    <%
    end if
    set objFs = Nothing
    %>
    --

    ngibsonau
  4. #3
  5. No Profile Picture
    MySQL Newbie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Melbourne, Australia
    Posts
    9
    Rep Power
    0
    thank you ngibsonau

    short.... sweet.... and accurate

    Ben.

IMN logo majestic logo threadwatch logo seochat tools logo