Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of insufficient php fopen authority

Shulou Source: shulou.com Published: 2022-06-02 22:33:14 10月02日 Update

This article mainly explains "how to solve the problem of insufficient php fopen permissions". The explanation content in the article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to solve the problem of insufficient php fopen permissions" together!

Php fopen permissions are not enough solutions: 1, open the terminal command window;2, in the terminal execute the command "sudo chmod 666 testOpen.php" can be.

Operating environment: linux 5.9.8 system, PHP 7.1 version, DELL G3 computer

PHP uses the fopen() function to open a file.

PHP fopen() function

Function Definition and Usage: The fopen() function opens a file or URL.

Grammar:

fopen(filename,mode,include_path,context)

The last two parameters are optional, we only use the first two parameters, the code is as follows:

The function of the code is to open a file named newfile.txt under the current path by writing, and try to create it if the file does not exist. After opening the file, write the Hello World string to the file and close the file.

There is no newfile.txt file under the current folder path. At this time, the error occurs when executing the above code as follows:

Warning: fopen(newfile.txt): failed to open stream: insufficient permissions in

/home/yums/web/blog_for_r&d/scripts/testOpen.php on line 3

Unable to open file!

Not enough authority? The most common problem with Linux is that you don't have permission to create files on your hard disk. I tried giving testOpen.php higher permissions, so I executed the following command in terminal:

sudo chmod 666 testOpen.php

This PHP file has the right to create a file, I try to refresh the page, WTF, or the original problem!

Warning: fopen(newfile.txt): failed to open stream: insufficient permissions in

/home/yums/web/blog_for_r&d/scripts/testOpen.php on line 3

Unable to open file!

Forget it, I don't use this function to create files, I use gedit to create my own newfile.txt file. So I executed the following command in terminal:

gedit newfile.txt

So I created a good file, and then refresh, or permissions are not enough, I still have a look at the newfile.txt file exactly what permissions it, in the terminal execute the following command:

ls -all

Found that newfile.txt created with Notepad only has read permission, no write permission, well, the problem is here, give newfile.txt file upgrade write permission:

sudo chmod 666 newfile.txt

Now refresh the page again, no error reported, the file also wrote the corresponding string.

Thank you for reading, the above is "how to solve php fopen permissions are not enough" content, after learning this article, I believe we have a deeper understanding of how to solve php fopen permissions are not enough, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: File permission not enough problem function command code or learning two content parameter character string path page try do not use method function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia Docker macOS Shulou Tech Info