What to do if php fopen reports an error

藏色散人
Release: 2023-03-10 08:56:01
Original
3208 people have browsed it

Solutions to php fopen error: 1. Modify the directory or folder permissions; 2. Modify the path to open the file; 3. Modify the php.ini configuration file.

What to do if php fopen reports an error

The operating environment of this article: centOS6.8 system, php version 7.2.2, DELL G3 computer

php fopen function returns false what to do?

Use yum to install apache2.4.6 php 7.2.2 After correct installation, it returns false when using the fopen() function to open the file

Baidu has three reasons

1. Reasons for directory or folder permissions

(You can use chmod -R 777 root directory and folder to set the highest permissions)

2. Error in opening file path

3. Opening method error (w, r, a), etc.

It has been determined that it is not the above error

Manually add 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

The error message returned is

failed to open stream: Permission denied
Copy after login

Prove that there is no permission

Switch to read-only mode and it can be opened normally

I guess PHP has restricted permissions

Search open_basedir in php.ini to view the configuration, the default is comment Lost, that is to say, there is no restriction on permissions

Finally, I found on various Baidu on the Internet

that selinux permission management is installed by default in the centos system, and it is enabled by default

I searched selinux on Baidu, and it seems that most of the introductions are to close it directly. It seems to be very troublesome to configure.

Then just turn it off

vim /etc/selinux/conf
Copy after login

You can see

SELINUX= enforcing
Copy after login

modifications For

SELINUX=disabled
Copy after login

Restart the server

Write the file again normally

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php fopen reports an error. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!