Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detailed error on fopen

I'm using fopen to read from a file

$fh = fopen($path, 'r') or die('Could not open file');

Now I contantly get error Could not open file. I checked the file path and even changed the permissions of the file to 777. Is there a way I can get a detailed error report as why the file can't be opened similar to mysql_error()?

like image 878
Elitmiar Avatar asked Sep 05 '25 03:09

Elitmiar


2 Answers

Turn on error reporting, or, in a production environment (from PHP 5.2.0 onwards) you should also be able to use error_get_last().

like image 51
Pekka Avatar answered Sep 07 '25 20:09

Pekka


For php versions prior to 5.2 (lacking error_get_last()) you can use track_errors.

ini_set('track_errors', 1);
$fh = fopen('lalala', 'r');
if ( !$fh ) {
  echo 'fopen failed. reason: ', $php_errormsg;
}

see also: http://de.php.net/reserved.variables.phperrormsg

like image 39
VolkerK Avatar answered Sep 07 '25 20:09

VolkerK