Results 1 to 9 of 9
  1. #1
    ABW Veteran Student Heyder's Avatar
    Join Date
    January 18th, 2005
    Posts
    5,482
    Is there any way for a php script to know if it's displaying a broken image? I don't mean non existant image I've taken care of that problem but I have broken image urls from manufacturers sites. Id like to replace them with my own image like the froogle.com does.

  2. #2
    "An Englishman In New York" TJ's Avatar
    Join Date
    January 18th, 2005
    Posts
    3,282
    Shhhhh.....don't say Froggle [img]/infopop/emoticons/icon_frown.gif[/img]

    [img]/infopop/emoticons/icon_biggrin.gif[/img] [img]/infopop/emoticons/icon_biggrin.gif[/img]

    I'd like to be able to do this too!

  3. #3
    Defender of Truth, Justice and the Affiliate Way
    Join Date
    January 18th, 2005
    Location
    The Swamp
    Posts
    7,503
    I have a php script that checks all my regular links and gives me back a report with the server response codes. I just ran it, and it doesn't check image links, but that's probably only because it is set up not to. If you know php, it could possibly be modified to check image url's also. I don't know php myself. [img]/infopop/emoticons/icon_wink.gif[/img] A goal of mine for next year.

    Keep Your Hands Off My Cookies

  4. #4
    ABW Ambassador FFoc's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,015
    Found on Zend code gallery:
    <pre class="ip-ubbcode-code-pre">&lt;?
    //idban secandri July 2000 please distribute is as GPL
    //
    //greeting as usual to desy, nadya, my friend at satunet group!

    $phpnet = fsockopen("www.php.net", 80, &$errno, &$errstr, 30);
    if(!$phpnet) {
    //change with your custom messages
    echo "php.net &lt;font color=\"red\"&gt;down!!&lt;/font&gt;\n"; }
    else {
    echo("&lt;a href=\"http://www.php.net\"&gt;php.net&lt;/a&gt;");
    }

    ?&gt;</pre>
    With this, you can check to see if the site serving the images is up, and alter your image tags accordingly...
    Obviously change the echos to bad and good img tags..

    A quick scan of the function reference on the php site doesn't turn up a url test function, but I'm sure there's one out there in an external library.

    [This message was edited by FFoc on December 15, 2002 at 02:07 AM.]

  5. #5
    ABW Veteran Student Heyder's Avatar
    Join Date
    January 18th, 2005
    Posts
    5,482
    Thanks FFoc

    That code almost works and might be a good idea for when an advertisers site goes offline. Just switch them out with another one.

    Does anyone know how to check the full url though?

  6. #6
    Newbie
    Join Date
    January 18th, 2005
    Posts
    16
    I'm not quite sure what you mean by check the full URL, but if you just want to ensure it meets the RFC specs, then you can use this function

    <pre class="ip-ubbcode-code-pre">
    function is_url($url)
    {
    return( preg_match('/(^(https?:\/\/)?([\w|\-][\.]{0,1})+\.[a-z]{2,4}(\/.*)?$)/i', $url) );
    }

    in your code, could be used like
    if(is_url('http://i.google.com/'))
    {
    do this;
    }
    </pre>

    If instead you meant to check the full url of an image, then FFoc's code from above will work, just substitute the url inplace of 'www.php.net'.

    <pre class="ip-ubbcode-code-pre">
    if(fopen('http://google.com/image.gif') === FALSE)
    {
    $image = broken;
    }
    else
    {
    $image = ok;
    }
    </pre>

    Hope this helps.

  7. #7
    ABW Ambassador CrazyGuy's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,463
    Heyder

    I don't know php, but wouldn't that FFoc code above work if you put the full image URL (www.php.net/testimage.gif) in place of just the domain?

    Looks to me like it's trying to http get the url, reading the status reported and then branching according to if the url is ok or not. Isn't that what you want to do?

    Are you Crazy?

  8. #8
    ABW Veteran Student Heyder's Avatar
    Join Date
    January 18th, 2005
    Posts
    5,482
    nope FFOC's code only works for wwwdomain.com it does not work for wwwdomain.com/any directory or images beyond the .com.

    Oh well I'm sure it's just more to learn. That's what it's all about.

    Let Fear Be Far from All

  9. #9
    ABW Ambassador FFoc's Avatar
    Join Date
    January 18th, 2005
    Posts
    1,015
    So far I've only built scripts to handle local images/files/etc., so I don't really know about checking offsite files..

    One thing I do know about is modularizing code - keep code you're going to reuse in a separate file, then call it using include() or require(), or if you're doing more than one included module in a script, use include_once() or require_once() to keep from bloating your script needlessly.

  10. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Broken Ad Images
    By BurgerBoy in forum Midnight Cafe'
    Replies: 45
    Last Post: March 17th, 2010, 01:14 PM
  2. Broken Images?
    By Daniel M. Clark in forum ShareASale - SAS
    Replies: 5
    Last Post: October 2nd, 2007, 02:08 PM
  3. Broken images
    By Haiko de Poel, Jr. in forum Midnight Cafe'
    Replies: 2
    Last Post: February 27th, 2003, 06:30 PM

Posting Permissions

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