Friday 15 April 2011

function - PHP Recursive File Loader -


I am trying to understand why this simple task is not going on, and it's time to see me Is it possible to find someone else who I am missing this function is a fairly simple snippet of code that will search again through a directory, it belongs to children, and this is children's children and so on Loading from and in PHP files are required to run the application.

As always, any guidance and assistance is appreciated. Thank you.

Code

  Global $ _ MWC; $ _MWC = array (); // Create an empty array to overwrite previously used data $ _MWC ['base'] = dynamism (__ file__); // Equal to "/ base" // Create a function that will load the required PHP files to run the application repeatedly. Function required_A_function ($ dir) {global $ _MWC; $ Scan = globe ($ _ MWC ['base']. '/'. $ Dir. '/ *'); Foreign currency ($ path $ scan as path) {If (preg_match ('/ .php $ /', $ path)) {require_once $ path; } Otherwise (is_dir ($ path)) {require_all_functions ($ path); }}} // Allows to load all the files in the editing directory for use in the system. Require_all_functions ('addon'); Print_r (get_included_files ()); // only for testing  

Output

  array ([0] => / base / addons / a .php)  

file structure

  /base/addons/a.php/base/addons/se1/b. Php / base / addons / sub1 / sub2 / c.php  

  • Find the folder in the current directory
  • Loop through them
  • Li> Call
  • Functional on all files
  • Add result to $ array array
  • $ file returned after returning to all folders and subfolders
  • Example:

      function glob_recursive ($ pattern) {$ files = glob ($ pattern, $ flags); $ / ($ Dir) as '/ *', GLOB_ONLYDIR | GLOB_NOSORT) $ $ files = array_merge ($ files, glob_recursive ($ dir. '/' .BusName (pattern $ pattern); foreach (glob (dirname ($ pattern).} $ Files;} $ PhpFiles = glob_recursive ($ _McC ['Base']. '/'. $ Dir. '/*.php'); Foreign Exchange ($ phpFiles as phpFile) {require_once $ phpFile;}  

    No comments:

    Post a Comment