PHP prompts that the permission is insufficient when using the fopen function to open the file.

Source: Internet
Author: User
: This article describes how to use the fopen function in PHP to open a file and prompt that the permission is insufficient. if you are interested in the PHP Tutorial, refer to it. PHP fopen () function

Function definition and usage: fopen () functions open files or URLs.
Syntax:

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 implemented by the code is to open a file named newfile.txt in the previous example in the write-in format. if the file does not exist, try to create it. After opening the file, write the Hello World string to the file and close the file.

When there is no newfile.txt file under the folder, the following error occurs when you execute the above code:

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!

Insufficient permissions? The most common problem in Linux is that you do not have the permission to create files on the hard disk? I tried to grant higher permissions to testOpen. php, so I executed the following command in terminal:

sudo chmod 666 testOpen.php

In this way, the PHP file has the permission to create the file. I will refresh the page and try again. WTF is still the 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!

After I created the file, I used gedit.pdf to create the newfile.txt file. So I executed the following command in terminal:

gedit newfile.txt

In this case, I have created a file, refreshed it, and got limited permissions. I also want to download the newfile.txt file and execute the following command in terminal:

ls -all

I found that the newfile.txtcreated with the upload script has only the read permission and no write permission. here is the question, so I can improve the write permission for the newfile.txt file:

sudo chmod 666 newfile.txt

Refresh the page now. no error is reported, and the corresponding string is written in the file.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces the problem that PHP prompts insufficient permissions to open a file using the fopen function, including some content. I hope to help some friends who are interested in PHP tutorials.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.