Hi Guys,
Just wondering what I'm doing wrong here: I have code that snakes through directorys and outputs the contents, and contents of subdirectorys. All is good. Now what I have here is the code with additional bits in that are meant to write to a document in the same structure as you'd get on an echo. If you replace the fputs with an echo you'll see what i mean.
<?
//replace fputs with an echo and view source - that's the intended structure!
$filename = "dir.xml";
$handle = fopen($filename, 'w');
//
function siteMap($siteRoot) {
if ($openDir = opendir($siteRoot)) {
while (false !== ($item = readdir($openDir))) {
if (is_dir($siteRoot . $item) && $item != "." && $item != "..") {
$folder = " <folder name = \"$item\">\n";
// errors formed on write part!
fputs($handle, $folder);
siteMap($siteRoot. $item. "/");
$folderClose = " </folder>\n";
// and here:
fputs($handle, $folderClose);
}
elseif (is_file($siteRoot . $item)) {
$node = " <file>$item</file>\n";
// and here:
fputs($handle, $node);
}
}
unset ($item);
closedir($openDir);
}
else
{
echo "Cannot open " . $siteRoot;
}
unset ($openDir);
}
siteMap("./");
//
fclose($handle);
?>
Is this a scope thing? I get error messages saying that the variable for $handle doesn't exist, even though it's declared in the second line. I thought references to variables were global? This is also the message I get aswell as the handle one
Warning: fputs(): supplied argument is not a valid stream resource in c:\inetpub\wwwroot\fileTest\test.php on line 19
Cheers