Results 1 to 5 of 5

Thread: IF image has loaded?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    IF image has loaded?

    I'd like to know the correct function/method to find out if an image has succesfully loaded on my website. So for instance if it hasn't loaded I want to show a standard image.

    Thanks

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: IF image has loaded?

    this is not possible with php (from what i know). I looked at the GD library on php.net, and didnt find any function for it. You might want to have a look yourself though.
    My usual boring signature: Something

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    From the UK
    Posts
    422

    Re: IF image has loaded?

    Wow I cant believe PHP doesnt have a function to support this! Are there are any other methods I can use to show a sample image if an image url doesnt load correctly on my site as otherwise there is just a huge white space!?

  4. #4
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: IF image has loaded?

    well you can check to see if the file exists, and if it doesnt then show another image...

    PHP Code:
    $file "img.png";
    if(
    file_exists($file)) {
         echo 
    "<img src='$file'>";
    } else {
         echo 
    "<img src='noimage.png'>";

    My usual boring signature: Something

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: IF image has loaded?

    Use the file_exists method to check if it exists on the server side. If it is guaranteed to then checking whether or not it loads properly is a purely client-side operation and PHP cannot help further.

    You can use the HTML <object> element to display an image with elements nested within as fallbacks. However, this is not very well supported by most browsers.

Posting Permissions

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



Click Here to Expand Forum to Full Width