php- how to disable warning on file_get_contents

Discussion in 'PHP' started by floopy, Jan 19, 2011.

  1. #1
    Hi,

    I'm facing this scenario:

    1. User inputs URL
    2. I have to check and return if URL exists

    How to do that?
    I came up with this

    error_reporting(0);
    if (file_get_contents($file)) return 'file exists'
    else return 'file doesnt exist' ;
    Code (markup):
    Since file_get_contents, much like fopen and other file functions throws a warning if file doesn't exist I had to put

    error_reporting(0)
    Code (markup):
    if front of it.

    Does anyone know of a better way to disable warning on file_get_contents?

    BR Gregor
     
    floopy, Jan 19, 2011 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    Error suppression.

    return (@file_get_contents($file)) ? 'file exists' : 'file doesnt exist' ;
    PHP:
     
    Alex Roxon, Jan 19, 2011 IP
    floopy likes this.
  3. BreezeTR

    BreezeTR Well-Known Member

    Messages:
    115
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #3
    $url = 'http://www.allaboutturkey.com';
       
          $handle = @fopen($url,'r');
       
          if($handle !== false){
       
          echo 'Exists';
       
          }
       
          else{
       
          echo "Doesn't";
       
          }
    PHP:
     
    BreezeTR, Jan 19, 2011 IP
  4. floopy

    floopy Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it works, thx.
     
    floopy, Jan 19, 2011 IP