php question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michael2002
    Confirmed User
    • Jan 2003
    • 145

    #1

    php question

    what is the best method to test if a file on a remote server (url) exist?

    currently i use something like :

    Code:
    if($x=file($url)) echo("file exist");
    else echo("file don't exist");
    but this code in the case that the file is not existing take long time to execute

    there is any faster method to test if a file on a remote server exist or not?
  • hyper
    Confirmed User
    • Mar 2002
    • 5294

    #2
    PHP Code:
    <?php
    $file = fopen ("http://www.example.com/", "r");
    if (!$file) {
        echo "<p>Unable to open remote file.\n";
        exit;
    }
    else {blah blah blah;
    }
    fclose($file);
    ?>

    Comment

    • Clarion
      Confirmed User
      • Jan 2005
      • 148

      #3
      Originally posted by hyper
      PHP Code:
      <?php
      $file = fopen ("http://www.example.com/", "r");
      if (!$file) {
          echo "<p>Unable to open remote file.\n";
          exit;
      }
      else {blah blah blah;
      }
      fclose($file);
      ?>
      change the first line to this so you don't generate any errors. $file = @fopen ("http://www.example.com/", "r");
      Structure Northwest :: the cure for the common code ::
      AIM: Asatruel | Yahoo!: Asatruel | ICQ: 111-638-053

      Comment

      • Aric
        Confirmed User
        • Sep 2002
        • 1209

        #4
        Don't forget the speed of the remote server is factored in here, not just your checking code.
        Awesome cloud hosting by DigitalOcean

        Comment

        Working...