failing php generating XML!
apotropaics_at_gmail.com
Date: 02/24/05
- Next message: John Smith: "Re: Picture resizing in PHP"
- Previous message: Michael Fesser: "Re: About editing a text file on my server with a URL call"
- Next in thread: Janwillem Borleffs: "Re: failing php generating XML!"
- Reply: Janwillem Borleffs: "Re: failing php generating XML!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Feb 2005 13:01:55 -0800
I'm trying to open a directory and create an XML file based on the
folder & file structure. Here is my code:
function imagefolder($imagedir,$level) {
if ($dir = opendir($imagedir)) {
$xmlcode = "";
$spacer = str_repeat(' ',$level);
while (($file = readdir($dir)) != false ) {
if ($file != ".") {
if ($file != "..") {
if (is_dir($dir ."/". $file)) {
echo("level is $level and file is $file and dir is $dirS");
$xmlcode = $xmlcode + $spacer + "<group id='".$level."'
title='".xmlReady($file)."'>".imagefolder($dir ."/".
$file,$level+1)."</group>\n";
}
else {
if (substr(strtolower($file,-3) == 'jpg')) {
$imageinfo = getimagesize($file);
$width = $imageinfo[0];
$height = $imageinfo[1];
$size = round(filesize($file)/1024,1).' KB';
$xmlcode = $xmlcode + $spacer +"<image id='".$level."'
title='".xmlReady($file)."' src='".$imagedir.$file."'
width='".$width."' height='".$height."' comments='".xmlReady($file)."'
/>\n";
}
}
}
}
}
closedir($dir);
}
return $xmlcode;
}
function jsalert($msg) {
echo ("<script language='javascript'>");
echo ("alert('".$msg."');");
echo ("</script>");
}
function xmlReady($str){
$str = str_replace("&", "&",$str);
$str = str_replace("<", "<",$str);
$str = str_replace(">", ">",$str);
$str = str_replace("'","'",$str);
$str = str_replace("\"", """,$str);
return $str;
}
////////////////////////////////////////////////////////////// DISPLAY
XML
header("Content-type: application/xml");
echo("<?xml version='1.0'?>\n");
echo("<catalog>\n");
//echo(display_children(0,0,$dbTable));
echo(imagefolder("./",0));
echo("</catalog>");
can anybody help me with this??? The output is basiclly just <catalog>
</catalog> sometimes I can get it to read just the folder and they do
display well inside of catalog elements.
- Next message: John Smith: "Re: Picture resizing in PHP"
- Previous message: Michael Fesser: "Re: About editing a text file on my server with a URL call"
- Next in thread: Janwillem Borleffs: "Re: failing php generating XML!"
- Reply: Janwillem Borleffs: "Re: failing php generating XML!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|