WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Directory Listing To XML : Outputs XML File of a Given Directory Listing
Categories : PHP, PHP Classes, XML, Directories Click here to Update Your Picture
MA Razzaque Rupom
Date : Jul 26th 2006
Grade : 5 of 5 (graded 7 times)
Viewed : 18417
File : 4472.zip
Images : No Images for this code example.
Search : More code by MA Razzaque Rupom
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This code
- traverses a directory path recursively and build an array from the list of files.
- creates XML data from that list of files
- saves it to XML file


DirectoryToXml.class.php
<?php

/**
* DirectoryToXml Class
*
* @PHPVER  :  5.0
* @author  :  MA Razzaque Rupom <rupom_315@yahoo.com>, <rupom.bd@gmail.com>
*             Moderator, phpResource (http://groups.yahoo.com/group/phpresource/)
*             URL: http://www.rupom.info 
* @version :  1.0
* @date    :  07/26/2006
* Purpose  :  Creating XML File of a Given Directory Listing
*/

include_once("class.array2xml2array.php");

class
DirectoryToXml extends CArray2xml2array
{
public
$arr;
private
$mainString;
private
$path;

/**
* Constructor
* @access public
* @param $path
*/

public function __construct($path)
{
   
$this->arr = array();
   
$this->mainString = "";
   
$this->path = $path;

}

/**
* Traverses Files in Directory
* @param $path to traverse
* @return none
*/
public function traverseDirFiles($path)
   {
     
$dir = opendir ($path);

      while (
$file = readdir ($dir))
      {
         if ((
$file == ".") or ($file == ".."))
         {
            continue;
         }

         if (
filetype("$path/$file") == "dir")
         {
           
$this->traverseDirFiles("$path/$file");
         }
         else
         {
           
$this->processFiles($path,$file);
         }
      }
//End of while

     
closedir($dir);

   }
//End of function
   
   /**
   * Put $file to path array
   * @param $path, $file
   * @return none
   */
   
function processFiles($path, $file)
   {

     if(
trim($path)==trim($this->path))
     {
       
$arr_to_form = 'this->arr[pathRoot]';
     }
     else
     {
         
$dat         = $this->formArray($this->path.$path);
         
$arr_to_form = 'this->arr[pathRoot]'.$dat;

     }

     
$searches = array("[","]");
     
$reps     = array("['", "']");
     
$arr_2    = str_replace($searches, $reps, trim($arr_to_form));
     

     
$vr = $arr_2.'[]';

     
//assigns $file to array "$arr"
     
eval("\$$vr=\"$file\";");


   }
//EOFn
   
   /**
   * Shows files and directories in a hierarchical structure from the given directory
   * @return none
   */
   
public function showDirHierarchy()
   {

     
$this->dBug($this->arr);
   }
   
   
/**
   * For Debuging/displaying purpose
   * @param data to debug
   * @return none
   **/
   
function dBug($dump)
   {
      echo
"<pre>";
     
print_r($dump);
      echo
"</pre>";
   }
   
   
/**
   * Forms path array from path string
   * @param path string
   * @return path array
   **/
   
function formArray($str)
   {
       
$arr = explode("$this->path/",$str);

       
$arr = explode("/",$arr[1]);

       foreach(
$arr as $i=>$v)
       {
         
$arr_to_form .= "[$v]";
       }
       
       return
$arr_to_form;
   }


}
//EO Class
?>




Usage Exmaple
<?php
     
/**
     * Usage of DirectoryToXml Class
     *
     * @PHPVER  :  5.0
     * @author  :  MA Razzaque Rupom <rupom_315@yahoo.com>, <rupom.bd@gmail.com>
     *             Moderator, phpResource (http://groups.yahoo.com/group/phpresource/)
     *             URL: http://www.rupom.info 
     * @version :  1.0
     * @date    :  07/26/2006
     * Purpose  :  Creating XML File of a Given Directory Listing
     */

     
include("DirectoryToXml.class.php");
     
     
//set path you want to get XML for
     
$path = "/home/projects/rupom/uploads/auction/httpdocs/admin"; //change it according to your need
     
     //Path to Array
     
$Obj = new DirectoryToXml($path);
     
$Obj->traverseDirFiles($path);
     
$Obj->showDirHierarchy();

     
//Array to XML
     
$Obj->setArray($Obj->arr);     
     
$xml_file = "test.xml";
     if (
$Obj->saveArray($xml_file))
     {
        echo
"<p><b>Array Converted To XML And Saved As $xml_file </b></p>";
     }

?>



XML easy parser
Categories : PHP, XML, PHP Classes
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
XPath for PHP without the DOM XML extension
Categories : DOM XML, XML, XSLT, PHP Classes, PHP
RSS parser. Parses RSS into an array. Quick and nasty but does the job. No checking is done for correct Tags, only correct XML. PHP4 needed to display result (uses print_r).
Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS)
PHP4 DirectoryIterator Class
Categories : PHP, PHP Classes, Filesystem, Directories
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
DBXML- A Class to backup databases in XML Format using web interface
Categories : PHP, PHP Classes, Databases, MySQL, XML
XML Menu
Categories : PHP, PHP Classes, Navigation, XML, XSL
A very basic and fast XML parser
Categories : PHP, PHP Classes, XML
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
logger class (PHP5 +)
Categories : PHP, PHP Classes, Log Files, XML
Listing the 10 most recently updated files in a given dir by using last- modified variable and printing to html with link to the file
Categories : PHP, Directories, Filesystem
PHP Composer - This class is meant to render images of the musical score of ring tones notes used in cellular phones, defined in the RTTL format.
Categories : PHP, PHP Classes, Misc
Request Method Class - seful for situations like form processing or API development. Requires PHP5 for the magic __call() method.
Categories : PHP, PHP Classes, HTTP, Headers
 Dave Silvia wrote : 1653
include_once("class.array2xml2array.php");

And this comes from where?
 
 Boaz Yahav wrote : 1654
Check out the file attached to this code exmaple.
 
 Ryan Blake wrote :1878
Very usefull for building large joomla component xml install files