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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Function to see if image exists?

    Hi,

    Is there a function that I can use to see whether an image exists?

    i.e. - I would like to see if 21656.jpg is exists - if it doesn't the text for that item would not be a link to the image.

    Thanks

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Use the file_exists() function

    PHP Code:
    <?php
    $img 
    "21656.jpg";

    if(
    file_exists($img)){
      echo 
    '<img src="' $img '">';
    }
    ?>

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

    I've already tried that - but it didn't like because the file reside on a different website.

    I have also tried -

    PHP Code:
    if (@fclose(@fopen("http://www.website.com/images/21656.jpg""r"))) {
         print(
    "File exists.");
    } else {
         print(
    "File does not exist.");
    }

    ?> 
    but it returns 'File does not exist' when it does if I cut and paste it into a browser window

    Any ideas?


  •  

    Posting Permissions

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