[PHP] Checking if an image exists on a remote server.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • darthmincho@gmail.com

    #1

    [PHP] Checking if an image exists on a remote server.

    Hi.
    I want to check if an image exists on a remote server, and if it does,
    show it. I
    If it does not exist I want to show a default message. I have
    previously used these chunks of code but none of them have worked. Any
    Ideas?

    ------------------------
    $imgCheck=readf ile("http.//www.somesite.co m/image.gif");
    if($imgCheck) echo "<img border=0
    src=\"http.//www.somesite.co m/image.gif\" width=\"550\" height=\"80\"
    alt=\"banner\"> ";
    -------------------------
    $fp = @fopen("http.//www.somesite.co m/image.gif","r") ;
    if ($fp) {
    echo '<img border=0 src="http.//www.somesite.co m/image.gif" width="550"
    height="80" alt="banner">';
    } else { echo 'Resource not valid'; }
    ------------------------
    Thanks ;o

  • frizzle

    #2
    Re: Checking if an image exists on a remote server.


    darthmincho@gma il.com wrote:[color=blue]
    > Hi.
    > I want to check if an image exists on a remote server, and if it does,
    > show it. I
    > If it does not exist I want to show a default message. I have
    > previously used these chunks of code but none of them have worked. Any
    > Ideas?
    >
    > ------------------------
    > $imgCheck=readf ile("http.//www.somesite.co m/image.gif");
    > if($imgCheck) echo "<img border=0
    > src=\"http.//www.somesite.co m/image.gif\" width=\"550\" height=\"80\"
    > alt=\"banner\"> ";
    > -------------------------
    > $fp = @fopen("http.//www.somesite.co m/image.gif","r") ;
    > if ($fp) {
    > echo '<img border=0 src="http.//www.somesite.co m/image.gif" width="550"
    > height="80" alt="banner">';
    > } else { echo 'Resource not valid'; }
    > ------------------------
    > Thanks ;o[/color]

    Dunno if that's it, but in your code you have
    HTTP.//
    instead of
    HTTP://

    Frizzle.

    Comment

    • darthmincho@gmail.com

      #3
      Re: Checking if an image exists on a remote server.

      Haha, no it isn't, ;)
      It was my fault because I typoed the http:// when writing the message
      onto the newsgroup lol. Sorry for that. I wrote that because I wanted
      to hide the URL.

      Comment

      • darthmincho@gmail.com

        #4
        Re: Checking if an image exists on a remote server.

        Bump!

        Comment

        • darthmincho@gmail.com

          #5
          Re: Checking if an image exists on a remote server.

          Bump!

          Comment

          • Rik

            #6
            Re: Checking if an image exists on a remote server.

            darthmincho@gma il.com wrote:[color=blue]
            > Bump![/color]

            Tsssk....


            But: if it doesn't work, why surpress error-messages?
            Turn off error-surpressing, put error_reporting (E_ALL) in your script, and
            me thinks you'll find the answer.

            Probably has something to do with allow_url_fopen .

            Grtz,
            --
            Rik Wasmus


            Comment

            • Jerry Stuckle

              #7
              Re: [PHP] Checking if an image exists on a remote server.

              darthmincho@gma il.com wrote:[color=blue]
              > Hi.
              > I want to check if an image exists on a remote server, and if it does,
              > show it. I
              > If it does not exist I want to show a default message. I have
              > previously used these chunks of code but none of them have worked. Any
              > Ideas?
              >
              > ------------------------
              > $imgCheck=readf ile("http.//www.somesite.co m/image.gif");
              > if($imgCheck) echo "<img border=0
              > src=\"http.//www.somesite.co m/image.gif\" width=\"550\" height=\"80\"
              > alt=\"banner\"> ";
              > -------------------------
              > $fp = @fopen("http.//www.somesite.co m/image.gif","r") ;
              > if ($fp) {
              > echo '<img border=0 src="http.//www.somesite.co m/image.gif" width="550"
              > height="80" alt="banner">';
              > } else { echo 'Resource not valid'; }
              > ------------------------
              > Thanks ;o
              >[/color]

              readfile() won't work because it echoes the output to the user (unless you've
              buffered it).

              fopen() should work, though.

              It would help if you told us what happens when you try.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              Working...