Page 199 - Open Soource Technologies 304.indd
P. 199

Open Source Technologies



                   Notes
                                   echo $ file. “\n”
                                   }

                                   }
                                   When you view the output of this script in your browser, you should see a list of the files
                                   in the named directory. How did this happen? Well, the Directory Iteratr class provieds a
                                   pre-built interface to iterating over the contents of a directory; once instantiated with the
                                   location of the target directory, it can then be processed as though it were a standard PHP
                                   array, with each element representing a file in the directory. Note the use of the is Dot 90
                                   method to filter out the “.” and “.” directories, respectively.

                                   Processing a Nested Directory Tree
                                   Recursively processing a nested directory tree is almost as simple. In this case, the Directory
                                   Iterator needs to check each object it encounters within the first-level directory, determine
                                   whether it is a file or directory, and, if a directory, drill one level deeper to examine the
                                   next level of contents. this sounds fairly complex, and in the past could easily add up to
                                   15-plus lines of code.
                                   With_PHP5, though, all you need are two iterators: the Recursive Directory Iterator and
                                   the  Recursivelterator  Iterator,  which  together  incorporate  all  the  above  functionality.
                                   Take a look at.
                                   Listing A

                                   Questions

                                   1. How Scan directories and PHP interrelated?
                                   2. What is processing a nested directory tree?


                                 11.8 Summary


                                    •  Validating the file helps to limit the file size.

                                    •  Fopen( ) is the command that opens the file for reading or writing. It accepts a file name
                                      and one of six arguments =r,rt, wt, a, at for unity of files.

                                    •  Deleting a file using PHP is done by using the unlink function.

                                    •  If you want to append to a file, i.e. add on to the existing data, them you need to open
                                      the file in append mode.

                                 11.9 Keywords


                                 CHMOD: It is a Unix command that lets you tell the system how much (or little) access it should
                                 permit to a file.








        194                               LOVELY PROFESSIONAL UNIVERSITY
   194   195   196   197   198   199   200   201   202   203   204