Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check if Image exists

    Hi,

    I'm passing through a customers id through a form.

    I have images stored of the customer named by their id in an 'images' folder.

    So - Customer ID '1' has a image 'images/1.jpg'.

    I can display the customers image by doing:

    <img src="images/<%= CustomerID %>" width="140" height="100"></td>

    where ID is:
    CustomerID = request.querystring("ID") & ".jpg"

    My question is - if the image doesn't exist in the images folder - can I show some text saying 'Image Required' instead of the little cross?

    Any help would be great

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use the FSO fileexists method:
    http://www.devguru.com/Technologies/...ileexists.html

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Raf,

    I'm trying to use that like this :

    FUNCTION FileExist(FileName)
    Dim FS, DoesExist
    DoesExist = FALSE
    SET FS=Server.CreateObject("Scripting.FileSystemObject")
    IF (FS.FileExists(FileName)) = TRUE THEN
    DoesExist = TRUE
    END IF
    SET FS=Nothing
    FileExist = DoesExist
    END FUNCTION


    <% IF FileExist(server.mappath("images") & "CustomerID") THEN %>
    <img src="images/<%= CustomerID %>" width="140" height="100"></td>
    <% else %>
    no file exists</td>
    <% end if %>


    But it doesn't like it - if you look at my previous post the CustomerID is appended to a '.jpg'

    can you see what i've doen wrong?

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe try something like
    Code:
    dim fileadr
    fileadr = "../images/" & request.querystring("ID") & ".jpg"
    ' comment : or "images/" & request.querystring("ID") & ".jpg" --> depending on where images is situated, relativaly to this file
    
    IF FileExist(server.mappath(fileadr) THEN 
      response.write("<img src="""& fileadr & """ width=""140"" height=""100"">") 
    else
      response.write("no file exists")
    end if
    response.write("</td>")

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Raf - got that working!!

    Cheers mate - you've been a great help!

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're welcome. Glad you got it working.

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    By the way, glenngv and I came up with a pretty cool client-side solution to this too (whether or not an image (or webpage!) exists, and ways to deal with using client-side javascript)...

    I suggested the idea, and he coded it perfectly (exactly what I was thinking!), if you can find it.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brilliant.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •