Specifications

FIGURE 16.3
The directory listing shows all the files in the chosen directory, including the . (the current directory) and .. (one level
up) directories. You can choose to filter these out.
If you are making directory browsing available via this mechanism, it is sensible to limit the
directories that can be browsed so that a user cannot browse directory listings in areas not nor-
mally available to him.
An associated and sometimes useful function is rewinddir($dir), which resets the reading of
filenames to the beginning of the directory.
As an alternative to these functions, you can use the dir class provided by PHP. This has the
properties handle and path, and the methods read(), close(), and rewind(), which perform
identically to the non-class alternatives.
Getting Info About the Current Directory
We can obtain some additional information given a path to a file.
The dirname($path) and basename($path) functions return the directory part of the path and
the filename part of the path, respectively. This could be useful for our directory browser, par-
ticularly if we began to build up a complex directory structure of content based on meaningful
directory names and filenames.
We could also add to our directory listing an indication of how much space is left for uploads
by using the diskfreespace($path) function. If you pass this function a path to a directory, it
will return the number of bytes free on the disk (Windows) or the file system (UNIX) that the
directory is on.
Advanced PHP Techniques
P
ART IV
360
21 7842 CH16 3/6/01 3:40 PM Page 360