Reading and Writing to Files
Communication with files follows the pattern of opening a stream to a file, reading from or writing to it, and then closing the stream. When you open a stream, you get an integer that refers to the open stream. Each time you want to read from or write to the file, you use this stream identifier. Internally PHP uses this integer to refer to all the necessary information for communicating with the file.
To open a file on the local file system, you use the fopen function. It takes a name of a file and a string that defines the mode of communication. This may be r for read-only or w for write-only, among other modes. It is also possible to specify an Internet address by starting the file name with http:// or ftp:// and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access