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.