Create a Primitive Error Handler
March 6, 2008PHP’s die() function is mostly used as a primitive error-handling mechanism.
In the event of a fatal error, die() can be used to terminate script processing
with an explanatory user-specified error message indicating the reason why.
The fopen(), fwrite(), and fread() functions are all binary-safe, which means you can use them on binary files without worrying about damage to the file contents.
Another way to do this is with the file_get_contents() function, new
in PHP 4.3.0 and PHP 5.0, which reads the entire file into a string.
Example Code:
<?php
// set file to read
$file = ‘/home/web/projects.txt’;
// read file into string
$data = file_get_contents($file) or die(’Could not read file!’);
// print contents
echo $data;
?>

