PHP using the fopen function to open the file prompt permission insufficient problem

Source: Internet
Author: User
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:


    
     //打开文件流$myfile = fopen("newfile.txt", "w")        ordie("Unable to open file!");//向文件中写入字符串fwrite($myfile, "Hello World");//关闭文件句柄fclose($myfile);?>

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

There is no Newfile.txt file under the current folder path, there is an error following executing 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!

Not enough authority? The most common problem with Linux, huh, is there no permission to create files on your hard disk? I tried to give testopen.php a higher privilege, so I executed the following command in Terminal:

sudo666 testOpen.php

So the PHP file has the right to create files, I will refresh the page to try, 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!

Well, I didn't use this function to create the file, I created the Newfile.txt file myself with Gedit. So I executed the following command in Terminal:

gedit newfile.txt

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

ls -all

Find the Newfile.txt created with Notepad only Read permissions, no write permission, OK, the problem is here, give Newfile.txt file elevation Write permission:

sudo666 newfile.txt

Now refresh the page, no error, the file is also written to the corresponding string.

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP using the fopen function to open the file prompt permission is insufficient, including the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.