If someone have a little knowledge of php can help with the php script bellow?
This script is read the files from the folder and export to xml…
[code]
<?php Class SCANDIR { //url base path public $path = ""; //contains folders and files public $folders = [], $files = []; //contain no-includes private $filters = [], $regexp = ""; //for tabs (readability) private $deep = 0, $tabs = ""; /* parameters: $path : path to file (relative path are allowed) $deep : how may tabs for printing beauty sake :) $filter : allowed types. if empty all files are listed */ function __construct( $path="./", $deep=0, $filters=["\\\\.html","\\\\.php"] ){ $this->path = $path; $this->filters = $filters; $this->regexp = '/'.implode('$|',$filters).'$/'; $this->deep = $deep; for ($i=0; $i<=$deep; $i++){ $this->tabs .= "\\t"; } return $this->scan(); } private function scan(){ $allfiles = scandir($this->path); foreach ($allfiles as $i => $d){ if ($d == '.' || $d == '..') continue; if (is_dir($this->path.$d)){ $this->folders[] = $d; } else{ if (empty($this->filters)) $this->files[] = $d; elseif (preg_match($this->regexp,$d)) $this->files[] = $d; } } return $this; } public function toText(){ //print files, then folders foreach ($this->files as $i => $f){ echo $this->tabs.$f."\ "; } foreach ($this->folders as $i => $f){ echo $this->tabs.$f."/\ "; $SD = new SCANDIR($this->path.$f.'/', $this->deep+1); $SD->toText(); } } public function toXML(){ if (empty($this->folders) && empty($this->files)){ return false; } $t = $this->tabs; //print files, then folders echo $t.''."\ "; if (!empty($this->files)){ echo $t.' '."\ "; foreach ($this->files as $i => $f){ echo $t.' '.utf8_encode($f).''."\ "; } echo $t.' '."\ "; } if (!empty($this->folders)){ echo $t.' '."\ "; foreach ($this->folders as $i => $f){ echo $t.' '."\ ". $t.' '.$f.'/'."\ "; $SD = new SCANDIR($this->path.$f.'/', $this->deep+1, $this->filters); $SD->toXML(); echo $t.' '."\ "; } echo $t.' '."\ "; } echo $t.''."\ "; } } $dirToScan = './'; $ScanDir = new SCANDIR($dirToScan, 0, ["\\\\.html","\\\\.php","\\\\.jpg","\\\\.png"]); if (isset($_GET['plaintext'])){ header('Content-Type: text/plain'); echo $dirToScan."\ "; $ScanDir->toText(); } elseif (isset($_GET['xml'])){ header('Content-Type: application/xml'); echo '<?xml version="1.0" encoding="UTF-8" ?>'."\“.
‘’.”
“.
‘’.”
“.
‘’.$dirToScan.”"."
“;
$ScanDir->toXML();
echo ‘’.”
".
‘’;
}
?>[/code]
The results is like this bellow.
I want to put a URL before the name like this <name>http://mypath/f1_01.png</name>
<scan>
<folders>
<name>./</name>
<scan>
<files>
<name>f1_01.png</name>
<name>f1_02.png</name>
</files>
</scan>
</folders>
</scan>
Any help would be appreciated !!