w Write only. Before writing, delete the file contents and return the file pointer to
the beginning of the file. If the file does not exist, attempt to create it.
w+ Read and write. Before reading or writing, delete the file contents and return
the file pointer to the beginning of the file. If the file does not exist, attempt to
create it.
a Write only. The file pointer is placed at the end of the file. If the file does not
exist, attempt to create it. This mode is better known as Append.
a+ Read and write. The file pointer is placed at the end of the file. If the file does
not exist, attempt to create it. This process is known as appending to the file.
b Open the file in binary mode.
t Open the file in text mode.
CHAPTER 10 ?– WORKING WITH T HE FILE A ND OPERATING SYSTEM 289
Let??™s consider a few examples. The first opens a read-only handle to a text file
residing on the local server:
$fh = fopen("/usr/local/apache/data/users.txt","rt");
The next example demonstrates opening a write handle to an HTML document:
$fh = fopen("/usr/local/apache/data/docs/summary.html","w");
The next example refers to the same HTML document, except this time PHP will
search for the file in the paths specified by the include_path directive (presuming
the summary.html document resides in the location specified in the previous example,
include_path will need to include the path /usr/local/apache/data/docs/):
$fh = fopen("summary.
Pages:
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363