I don't think there is a need to use $x. In general it is not a good idea to use globals in recursive functions. I have no possibility to test my code, but you could try this:
function list_dir($handle, $path, $x = 0) {
// Loop over the directory and don\"t display certain files
echo "<ul>";
//running the while loop
while (false !== ($file = readdir($handle))) {
$extension = strtolower(substr(strrchr($file, '.'), 1));
$dir =$path.'/'.$file;
if(is_dir($dir) && $file != '.' && $file !='..' ) {
$handle = opendir($dir) or die("unable to open file $file");
echo "<li><b>$file</b></li>";
$x = list_dir($handle, $dir, $x);
}
elseif($extension == "zip") {
unlink($file);
}
elseif($extension == "mp3" || $extension == "mpa" && $file != '.' && $file !='..') {
echo "<li><input type = \"checkbox\" name = \"file$x\" value = \"$file\" /><input type = \"hidden\" name = \"file".$x."_path\" value = \"".$path."\" /><a href=\"".$path."/$file\">$file</a></li>";
}
$x++;
}
echo "</ul>";
return $x;
}
Last edited by pritaeas; Sep 18th, 2009 at 9:26 am.
Reputation Points: 549
Solved Threads: 722
Bite my shiny metal ass!
Offline 4,156 posts
since Jul 2006