Php knowledge?(Solved)

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 !!

What have you tried that hasn’t worked?
If you want to add the same url prefix to all the files you can add it to the literal string.

Hi Tim…
I don’t have any knowledge of php at all and yes i want the prefix to all the files…
I have read about strings something like this i thing “myUrl”,but i don’t know where i put it :slight_smile:

Try changing utf8_encode($f) to utf8_encode($this->path.$f)

		if (!empty($this->files)){
			echo $t.'  <files>'."\
";
				foreach ($this->files as $i => $f){
					echo $t.'    <name>'.utf8_encode($this->path.$f).'</name>'."\
";
				}
			echo $t.'  </files>'."\
";
		}

Thank you Tim…i try just now the result is

<name>./f1_25.png</name>

Fixed i changed the $this->Path with a string :slight_smile:

<name>http://myurl/f1_01.png</name>

Ok, so maybe to clarify, what did you mean by “mypath” in your question? Is that a fixed base url? You may need to add that as well, something like

utf8_encode(“http://mypath”.$this->path.$f)

And you may need to tweak $this->path in order to eliminate a relative path.

[quote=295934:@Tim Hare]Ok, so maybe to clarify, what did you mean by “mypath” in your question? Is that a fixed base url? You may need to add that as well, something like

utf8_encode(“http://mypath”.$this->path.$f)

And you may need to tweak $this->path in order to eliminate a relative path.[/quote]

Yes was a fixed base url…
With your help i have resolve the problem.
Thank you.

Make sure it works with subdirectories (depth > 0). You will need at least part of $this->path to handle them properly.

Of course, if you never call it with anything but depth 0, you’ll be fine.