PHP
  Home arrow PHP arrow Page 3 - 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 - Recursively including PHP files
    ( Page 3 of 4 )

     

    As I explained in the segment that you just read, the best way to understand how the previous “Loader()” class functions is by developing some concrete examples that show how to use it. So, since the class’s main task is to include required files dynamically, I’m going to use the two sample files created in preceding articles. They looked like this:

     

    ('sample_file1.php')

     

    <?php

    echo ' This file has been loaded with the Loader class.' . '<br />';

    ?>

     

     

    ('sample_file2.php')

     

    <?php

    echo 'This file has been loaded at the following time: ' . date('H:i:s');

    ?>

     

    Now that there are two files available to be included by the loader class, it’s time to create a hypothetical scenario. Say the files in question are located on a directory called “folder1” on the web server (yes, my creativity really blows me away sometimes, especially when it comes to naming directories in a fancy way), which is one level below the location at which the loader class resides. 

    Based on this simple directory hierarchy, it’s perfectly possible to code an example where the loader class includes the two previous files after performing a recursive search. The corresponding code sample would look as follows:

     

    // 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'] . '/folder1);

    // 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 20:33:25

    */

     

    From the example shown above, it’s clear to see how the loader class really works. In this specific case, the starting path we use to look for a required file is simply the aforementioned “folder1” directory, which is located one level below the web server’s root -- but naturally the path can be easily modified and make the class seek for other locations. 

    Once the appropriate path has been set, the pertinent “load()” method is called dynamically to include  the “sample_file1.php” file, and then the remaining one, called “sample_file2.php.” This demonstrates the actual functionality of the “Loader” class when it comes to including specified files using a recursive search. 

    While the previous example should be illustrative enough to show how the loader class does its thing, I’d like to finish this tutorial by creating a final code sample that demonstrates the capability of the class when the targeted files to be included are located two levels below the web server’s root. 

    This wrapping example will be developed in the last segment of the article. Please click on the link that appears below and read the next few lines. We’re almost finished!



     
     
    >>> 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 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek