Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output the reason for a PHP file open failure

I'm trying to debug a huge, antiquated (circa 2001) PHP web service and I'm encountering file open failures. The fopen call is in an included module, the caller is logging that the file could not be opened but no reason is being logged.

The code that actually does the open is:

  // Read the file
  if (!($fp = @fopen($fileName, 'rb'))) {
    $errStr = "Failed to open '{$fileName}' for read.";
    break; // try-block
  }

How can I find out why fopen failed?

like image 889
user24989 Avatar asked Feb 03 '23 10:02

user24989


1 Answers

Take away the @ sign.

The @ sign suppresses error messages, so it is supressing the error the the function would normally give.

like image 165
Tyler Carter Avatar answered Feb 06 '23 14:02

Tyler Carter