Read file without php error messages

If you're using php to read the contents of various files in order to construct a web page, you don't want a missing file to result in error messages all over the web page. Use the error control operator and a conditional to prevent this happening:

$filename = 'thefile';
if ($file = @fopen($filename, 'r')) {
  while(!feof($file)) {
    echo fgets($file);
  }
  fclose($file);
}
else {
  echo 'Unable to open '.$filename;
}
Last modified: 09/09/08 17:31:54
Go to top

Related Pages

No related pages or links.

Login/out

Login

Forgot Password?
Go to top
Go to top