|
|
|
|
|
|
| |
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>";
}
?> | | |
|
| 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) | | | A very basic and fast XML parser Categories : PHP, PHP Classes, XML | | | XML Menu Categories : PHP, PHP Classes, Navigation, XML, XSL | | | 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 | | | DBXML- A Class to backup databases in XML Format using web interface Categories : PHP, PHP Classes, Databases, MySQL, 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 | | | 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 | | | XML To Array Categories : PHP, PHP Classes, XML, Arrays | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | |
| | | | 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.
| |
|
|
|