7.0 Introduction


Directories allow for the organization of related data. Instead of having all programs and files in one area, directories enable you to categorize and subcategorize your data in a sane form. This strategy is the basis of both the Windows and the UNIX filesystems. PHP provides a standard set of features for manipulating and searching directories.

In fact, if you are a C programmer, you should feel right at home with PHP's support for directory access. Besides the basic differences between C and PHP, the functions and methods for accessing directory trees are fundamentally the same. Consider the following example:

 <?php $dh = opendir ('/usr/home/designmm/public_html/'); while ($file = readdir ($dh)) {     print "$file\n"; } closedir ($dh); ?> 

This would loop through all the files in the html/ directory and print them out on a line. Seem familiar? It should, it is basically the same way you loop through a file using fopen() , fgets() , and fclose() , but now we use opendir() , readdir() , and closedir() .

This chapter covers both directories and how to modify their contents with PHP's filesystem functions.



PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net