What to do if php fopen returns an error code

藏色散人
Release: 2023-03-11 06:44:01
Original
2713 people have browsed it

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.

What to do if php fopen returns an error code

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');
Copy after login

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");
Copy after login

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= .
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template