Can someone please help me with this recursive function! It's messing up the incrementing of $x. I don't know what's wrong and I've been looking at it for so long now.
function list_dir($handle, $path) {
// Loop over the directory and don\"t display certain files
global $x;
$x = 0;
echo "<ul>";
//running the while loop
while (false !== ($file = readdir($handle))) {
$extension = strtolower(substr(strrchr($file, '.'), 1));
$dir =$path.'/'.$file;
global $file_path;
$file_path[$x] = $path;
if(is_dir($dir) && $file != '.' && $file !='..' ) {
$handle = opendir($dir) or die("unable to open file $file");
echo "<li><b>$file</b></li>";
list_dir($handle, $dir);
}
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 = \"".$file_path[$x]."\" /><a href=\"".$file_path[$x]."/$file\">$file</a></li>";
}
$x++;
}
echo "</ul>";
}