288 CHAPTER 10 ?– WORKING WITH THE FI LE AND OPERATING SYSTEM
Opening a File
The fopen() function binds a file to a handle. Once bound, the script can interact with
this file via the handle. Its prototype follows:
resource fopen(string resource, string mode [, int use_include_path
[, resource zcontext]])
While fopen() is most commonly used to open files for reading and manipulation,
it??™s also capable of opening resources via a number of protocols, including HTTP, HTTPS,
and FTP, a concept discussed in Chapter 16.
The mode, assigned at the time a resource is opened, determines the level of access
available to that resource. The various modes are defined in Table 10-1.
If the resource is found on the local file system, PHP expects it to be available by
the path prefacing it. Alternatively, you can assign fopen()??™s use_include_path
parameter the value of 1, which will cause PHP to look for the resource within the
paths specified by the include_path configuration directive.
The final parameter, zcontext, is used for setting configuration parameters specific to
the file or stream and for sharing file- or stream-specific information across multiple
fopen() requests. This topic is discussed in further detail in Chapter 16.
Table 10-1. File Modes
Mode Description
r Read-only. The file pointer is placed at the beginning of the file.
r+ Read and write. The file pointer is placed at the beginning of the file.
Pages:
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362