The solution to the error code returned by php fopen: first manually add a PHP error report; then modify the restrictions on PHP access to the directory in the php configuration file php.ini.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
What should I do if php fopen returns an error code?
PHP fopen failed and returned false
I encountered the problem on December 14th. I just took some time to record it today. I hope it will be helpful to other friends who encounter this problem. .
$fH = fopen("/tmp/test.log",'a');
In the above line of code, fopen actually returns false. It is neither a directory or file permissions-related issue, nor a file path issue (relative path, absolute path), etc., nor is it an issue with the mode of opening the file (r, w ,a etc.).
After searching online for a while, I found that the reason for returning false is one of the three situations above, so I couldn't find the answer.
So I added a PHP error report:
//error handler function function customError($errno, $errstr){ echo "<b>Error:</b> [$errno] $errstr"; } //set error handler set_error_handler("customError");
I found the reason immediately:
It turns out that I made the PHP access directory in the php configuration file php.ini Restrictions:
open_basedir= .
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if php fopen returns an error code. For more information, please follow other related articles on the PHP Chinese website!