File open with exception checking : fopen « File Directory « PHP
- PHP
- File Directory
- fopen
File open with exception checking
<?php
try {
$fh = fopen("data.txt", "r");
if (! $fh) {
throw new Exception("Could not open the file!");
}
}
catch (Exception $e) {
echo "Error (File: ".$e->getFile().", line ".
$e->getLine()."): ".$e->getMessage();
}
?>
Related examples in the same category