PHP implementation method for opening files as read-only
This article mainly introduces the PHP implementation to open the file in a read-only way, the example analysis of PHP fopen function and the use of skills, the need for friends can refer to the following
The example in this article describes how PHP implements open files as read-only. Share to everyone for your reference. The specific analysis is as follows:
PHP can open a file through fopen (), the second parameter is set to "R" to indicate that it is read-only open, the function returns a file handle, and other functions can read the file in different ways through this file handle
?
1 2 3 4 5 6 |
$file = fopen ("/tmp/file.txt", "R"); Print ("Type of File Handle:".) GetType ($file). "\ n"); Print ("The first line from the file handle:".) Fgets ($file)); Fclose ($file); ?> |
The above code returns the following result
Type of File Handle:resource
The first line from the file handle:welcome to sharejs.com PHP tutorials
After the file read is complete, you need to close the file handle using the Fclose () function to free up resources
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/968672.html www.bkjia.com true http://www.bkjia.com/PHPjc/968672.html techarticle PHP Implementation method of opening a file as read-only this article mainly introduces the PHP implementation to open the file in a read-only way, the example analysis of PHP fopen function and the use of skills, need ...