PHP
  Home arrow PHP arrow Page 4 - Including Files Recursively with Loader Applications in PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Including Files Recursively with Loader Applications in PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2009-06-11


    Table of Contents:
  • Including Files Recursively with Loader Applications in PHP
  • Review: the loader() class so far
  • Recursively including PHP files
  • Changing the location of required files

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Including Files Recursively with Loader Applications in PHP - Changing the location of required files
    ( Page 4 of 4 )

      

    I’d like to end this fourth part of the series by showing you one last example that illustrates how the loader class can be capable of including the same sample files that you saw in the previous section -- but this time, these files are placed under a directory that’s located two levels below the web server’s root. 

    To demonstrate the recursive search abilities of the class in a case like this, below I included another code sample, where the files to be included now reside in a fictional new folder called “folder2.” Study the following example closely to grasp how it works:

     

    // create instance of Loader class

    $loader = new Loader();

    // set file to load

    $loader->set_file('sample_file1.php');

    // set path of specified file

    $loader->set_path($_SERVER['DOCUMENT_ROOT']);

    // try to load specified file

    $loader->load($loader->get_file(), $loader->get_path());

    // set another file to load

    $loader->set_file('sample_file2.php');

    // try to load specified file

    $loader->load($loader->get_file(), $loader->get_path());

     

    /* displays the following

    This file has been loaded with the Loader class.

    This file has been loaded at the following time 22:21:09

    */

     

    As you can see above, even when the sample files to be included now are located in a directory that’s two levels below the root of the web server, the loader class will load them successfully regardless of their location, thanks to the recursive method it employs to perform the inclusion process. 

    Also, you may want to create your own examples with the loader class. Try putting your required files at different locations on the file system, and see how the class does a recursive search with the new supplied path. This exercise will be helpful for sharpening your skills in building loading programs with PHP 5. 

    Final thoughts 

    Over the course of this fourth article of the series, I proceeded to create some basic examples that hopefully demonstrated the actual functionality of the file loader class that you saw previously. 

    As you saw in the examples, the class was capable of including a specific file or resource in a recursive way, as long as the file in question was located at the same level and below of the starting search path. This makes it a flexible and effective loading mechanism. 

    In the article to come, I’m going to discuss how to take advantage of the functionality provided by the loader class, but without having to create an instance of it. 

    Don’t miss the next part!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Adding Ordering and Grouping Clauses to the ...
    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek