www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to find if a remote image exists or can be displayed?

  1. #1
    Join Date
    Mar 2008
    Posts
    70

    Question How to find if a remote image exists or can be displayed?

    I've been using this function to check for broken images and it works for most of them but it says that some don't exist when they do display fine on my website.

    PHP Code:
    function remote_file_exists($url)
    {
        
    $curl curl_init($url);
        
        
    //don't fetch the actual page, you only want to check the connection is ok
        
    curl_setopt($curlCURLOPT_NOBODYtrue);
        
        
    //do request
        
    $result curl_exec($curl);
        
        
    $ret false;
        
        
    //if request did not fail
        
    if($result !== false)
        {
            
    //if request was ok, check response code
            
    $statusCode curl_getinfo($curlCURLINFO_HTTP_CODE);  
            
            if (
    $statusCode == 200)
            {
                
    $ret true;   
            }
        }
        
        
    curl_close($curl);
        
        return 
    $ret;

    For example this image shows up fine but I can't detect that it exists:

    http://www.dailystab.com/blog/wp-con...y-johnson1.JPG

    also getimagesize() has the same problem, it can't get the size but the image displays fine.

    How can I find if an image will display in the browser without checking by hand?

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    Works fine for me when I run it from my server using that image's URL (as does getimagesize()).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles