How to check remote file...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sree

    How to check remote file...

    Hi,


    i want to check whether a file from remote server is existed or
    not.

    The file_exists() checks for local server only. But i want a function
    that checks the remote server.


    If anyone knows please help..

    thanks in advance...

    regards
    sree

  • Rik

    #2
    Re: How to check remote file...

    sree wrote:
    Hi,
    >
    >
    i want to check whether a file from remote server is existed or
    not.
    >
    The file_exists() checks for local server only.
    Actually, starting at PHP5 it will work on some url's.
    But i want a function
    that checks the remote server.
    >
    If anyone knows please help..
    >
    thanks in advance...
    I'm not sure exactly how. You could possibly use fsockopen en send a HTTP HEAD
    request, and check the response. There may be better options in curl available.

    Grtz,
    --
    Rik Wasmus


    Comment

    • sree

      #3
      Re: How to check remote file...


      Hi Rik,

      Do you know the exact options curl???




      Rik wrote:
      sree wrote:
      Hi,


      i want to check whether a file from remote server is existed or
      not.

      The file_exists() checks for local server only.
      >
      Actually, starting at PHP5 it will work on some url's.
      >
      But i want a function
      that checks the remote server.

      If anyone knows please help..

      thanks in advance...
      >
      I'm not sure exactly how. You could possibly use fsockopen en send a HTTP HEAD
      request, and check the response. There may be better options in curl available.
      >
      Grtz,
      --
      Rik Wasmus

      Comment

      • Chung Leong

        #4
        Re: How to check remote file...

        sree wrote:
        Hi,
        >
        >
        i want to check whether a file from remote server is existed or
        not.
        >
        The file_exists() checks for local server only. But i want a function
        that checks the remote server.
        >
        >
        If anyone knows please help..
        >
        thanks in advance...
        >
        regards
        sree
        This will do the trick:

        if(@fopen($url, "rb")) {
        }

        Comment

        • sree

          #5
          Re: How to check remote file...

          Hi,

          No probs. I got the solution for this.

          that is,

          <?php
          $TheImage = "http://www.uk-present.co.uk/images/logo.gif";
          if (@fclose(@fopen ("$TheImage" , "r"))) {
          $TheImage = "$TheImage" ;
          }
          else {
          $TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
          }
          ?>

          The first if loop tells you that the image exist, else it does not
          exist



          However it works only when the server gives you 404 error



          Chung Leong wrote:
          sree wrote:
          Hi,


          i want to check whether a file from remote server is existed or
          not.

          The file_exists() checks for local server only. But i want a function
          that checks the remote server.


          If anyone knows please help..

          thanks in advance...

          regards
          sree
          >
          This will do the trick:
          >
          if(@fopen($url, "rb")) {
          }

          Comment

          • Jerry Stuckle

            #6
            Re: How to check remote file...

            sree wrote:
            Hi,
            >
            No probs. I got the solution for this.
            >
            that is,
            >
            <?php
            $TheImage = "http://www.uk-present.co.uk/images/logo.gif";
            if (@fclose(@fopen ("$TheImage" , "r"))) {
            $TheImage = "$TheImage" ;
            }
            else {
            $TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
            }
            ?>
            >
            The first if loop tells you that the image exist, else it does not
            exist
            >
            >
            >
            However it works only when the server gives you 404 error
            >
            >
            >
            Chung Leong wrote:
            >
            >>sree wrote:
            >>
            >>>Hi,
            >>>
            >>>
            >> i want to check whether a file from remote server is existed or
            >>>not.
            >>>
            >>>The file_exists() checks for local server only. But i want a function
            >>>that checks the remote server.
            >>>
            >>>
            >>>If anyone knows please help..
            >>>
            >>>thanks in advance...
            >>>
            >>>regards
            >>>sree
            >>
            >>This will do the trick:
            >>
            >>if(@fopen($ur l, "rb")) {
            >>}
            >
            >
            You shouldn't call fclose() on a file handle which never opened. It's
            an error - which you're hiding with the @. But the error still occurs,
            is still logged and still takes system resources to handle. Better would be:

            <?php
            $TheImage = "http://www.uk-present.co.uk/images/logo.gif";
            if (($fh = fopen("$TheImag e", "r"))) {
            $TheImage = "$TheImage" ;
            fclose($fh);
            }
            else {
            $TheImage = "http://www.uk-present.co.uk/images/120x60-noimage.gif";
            }
            ?>

            Generally, if you have to use '@' you should look at why you need to use it.

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

            Comment

            • Chung Leong

              #7
              Re: How to check remote file...

              sree wrote:
              >
              However it works only when the server gives you 404 error
              >
              Call stream_get_meta _data() on the file handle returned and parse the
              wrapper_data array. That contains the HTTP response header, with the
              status code in first element.

              Comment

              Working...