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 8 of 8

Thread: Image Exists?

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post

    Image Exists?

    I need to check to see if an image exists on a remote server and if it does, show it. This is what I have tried:


    $imgCheck=readfile("http://$domainid:8900/$courseid/images/banner.jpg");
    if($imgCheck) echo "<img border=0 src=\"http://$domainid:8900/$courseid/images/banner.jpg\" width=\"550\" height=\"80\" alt=\"banner\">";


    So far I can't get it to work out. What I am I missing

  • #2
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $fp = @fopen("http://$domainid:8900/$courseid/images/banner.jpg","r");
    if (
    $fp) {
        echo 
    '<img border=0 src="http://'.$domainid.':8900/'.$courseid.'/images/banner.jpg" width="550" height="80" alt="banner">';
    } else { echo 
    'Resource not valid'; } 
    Last edited by Feyd; 07-08-2002 at 10:21 PM.
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hmmm...When I try that it tells me it is not a valid resourse yet the resource is there. When I take out the @ to check for error messages I get:

    Warning: fopen("http://161.28.224.167:8900/BMC_2250IN02/images/banner.jpg","r") - Success in /web/htdocs/uvnet/PHP/WebCT/openfeedback.php on line 45

    If I just use:

    echo '<img border=0 src="http://'.$domainid.':8900/'.$courseid.'/images/banner.jpg" width="550" height="80" alt="banner">';

    where I know there is an image it will show the image, yet if I try to detect it using fopen or readfile it fails. We have several hundred places to check and some of them have the new banner set up and some of them don't, I just want to write one page to deal with it all.

  • #4
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Weird...works for me...wait, you've got password protection on that dir. Are all of these on the same box/ip?
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #5
    Regular Coder Feyd's Avatar
    Join Date
    May 2002
    Location
    Los Angeles, CA Maxim: Subvert Society
    Posts
    404
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or you could do

    PHP Code:
    if($img = @GetImageSize('http://'.$domainid.':8900/'.$courseid.'/images/banner.jpg')) {
        echo 
    'image exists';
    } else {
        echo 
    'image does not exist';

    But you are still going to get into the user auth problem (which is why it is telling you it doesn't exist) unless you hardcode the auth into this script (which could be bad juju), or open the file directly on the server file level as opposed to ip/URL. (or you could wrap it in a login)
    Moderator, Perl/CGI Forum
    shadowstorm.net - subvert society

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Unfortunently they are on diferent servers. When I try this:

    if($img = @GetImageSize('http://Username:Password@'.$domainid.':8900/'.$courseid.'/images/banner.jpg')) {
    echo 'image exists';
    } else {
    echo 'image does not exist';
    }

    it still fails. However if I just enter this into the adress bar it works:

    http://Username:Password@courseinfo.uvsc.edu:8900/BMC_2250IN02/images/banner.jpg
    Last edited by JohnKrutsch; 07-08-2002 at 11:34 PM.

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    have a play with the snoopy class ...

    http://snoopy.sourceforge.com


    this just grabs the image contents, but you should be able to elicit a true or false out of this...

    PHP Code:
    <?
    include "Snoopy.class.inc";
        
    $snoopy = new Snoopy;
        
    //$snoopy->user = "joe";
        //$snoopy->pass = "bloe";
        
        
    if($snoopy->fetch("http://www.firepages.com.au/img/v4.jpg"))
        {
            echo 
    "response code: ".$snoopy->response_code."<br>\n";
            echo 
    $snoopy->results;
        
        }
        else
            echo 
    "error fetching document: ".$snoopy->error."\n";
    ?>
    I am not sure if getimagesize() works on remote files and I assume that you need fopen wrappers turned on if it actually does.

    Another interested point, you would need to do something with the code above to chek the content (perhaps the returned headers?) as when you attempt to open a file that does not exists, you still get an OK response, I assume as the web-server dishes out a 404 if the file is not found, I know that snoopy can return just the headers though and this should do the trick??
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    this should work ... you just have to check the $arr array for 'image/jpeg' etc.

    PHP Code:
    <?
    include "Snoopy.class.inc";
        
    $snoopy = new Snoopy;
        
        
    //$snoopy->user = "joe";
        //$snoopy->pass = "bloe";
        
        
    if($snoopy->fetch("http://www.firepages.com.au/img/v4.jpg"))
        {
            echo 
    "response code: ".$snoopy->response_code."<br>\n";
            
    $arr=$snoopy->headers;
            while(list(
    $key,$var)=each($arr)){echo "$key , $var<br>";}
    }
        else
            echo 
    "error fetching document: ".$snoopy->error."\n";
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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