What to do if the php fopen function fails

藏色散人
Release: 2023-03-09 07:44:01
Original
2966 people have browsed it

The solution to the failure of the php fopen function: first add a PHP error report through "set_error_handler("customError");"; then modify the restrictions on PHP's access to the directory in the php configuration file php.ini.

What to do if the php fopen function fails

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

PHP fopen fails and returns false

I encountered a 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 simply 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= .

[Recommended learning: PHP video tutorial]

The above is the detailed content of What to do if the php fopen function fails. 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