Otherwise, whence can be set to one of three possible values,
which affect the pointer??™s position:
CHAPTER 10 ?– WORKING WITH T HE FILE A ND OPERATING SYSTEM 299
SEEK_CUR: Sets the pointer position to the current position plus offset bytes.
SEEK_END: Sets the pointer position to the EOF plus offset bytes. In this case,
offset must be set to a negative value.
SEEK_SET: Sets the pointer position to offset bytes. This has the same effect as
omitting whence.
Retrieving the Current Pointer Offset
The ftell() function retrieves the current position of the file pointer??™s offset within
the resource. Its prototype follows:
int ftell(resource handle)
Moving the File Pointer Back to the Beginning of the File
The rewind() function moves the file pointer back to the beginning of the resource.
Its prototype follows:
int rewind(resource handle)
Reading Directory Contents
The process required for reading a directory??™s contents is quite similar to that involved in
reading a file. This section introduces the functions available for this task and also
introduces a function new to PHP 5 that reads a directory??™s contents into an array.
Opening a Directory Handle
Just as fopen() opens a file pointer to a given file, opendir() opens a directory stream
specified by a path. Its prototype follows:
resource opendir(string path)
Closing a Directory Handle
The closedir() function closes the directory stream.
Pages:
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373