Could someone have a look at this code and try to figure out what's wrong??
(the problem occurs when you've clicked a sub folder and clicks on the same sub_folder. For some reason the variable "pre" isn't passed on the currently "open" directory in the structure)
<?
$root = "D:/musicfolder/";
$img = "<img src='/images/folder.gif'>";
$dir = $_GET['dir'];
/*
dir looks like this dir[]=sub_folder1&dir[]=sub_folder2 etc.
*/
function sub_dir($path)
{
if(!file_exists($path))
return 0;
$arr = array();
if ($handle = opendir($path))
{
while (false !== ($found_dir = readdir($handle)))
{
if ($found_dir !== "." && $found_dir !== ".." && is_dir($path.$found_dir))
{
$arr[count($arr)] = $found_dir;
}
}
}
return $arr;
}
function dir_structure($path,$count,$pre)
{
global $img;
global $dir;
for($i=0;$i<$count;$i++)
$add = $add." ";
$a_dir = sub_dir($path);
for($i=0;$i<count($a_dir);$i++)
{
if($a_dir[$i] == $dir[$count])
{
echo $add.$img."<a href='?dir[]=".$a_dir[$i]."'>".$a_dir[$i]."</a><br>";
dir_structure($path.$a_dir[$i]."/",($count+1),$pre."dir[]=".$a_dir[$i]."&"
;
}
else
{
echo $add.$img."<a href='?".$pre."dir[]=".$a_dir[$i]."'>".$a_dir[$i]."</a><br>";
}
}
}
dir_structure($root,0,""
;
?>
My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
(the problem occurs when you've clicked a sub folder and clicks on the same sub_folder. For some reason the variable "pre" isn't passed on the currently "open" directory in the structure)
<?
$root = "D:/musicfolder/";
$img = "<img src='/images/folder.gif'>";
$dir = $_GET['dir'];
/*
dir looks like this dir[]=sub_folder1&dir[]=sub_folder2 etc.
*/
function sub_dir($path)
{
if(!file_exists($path))
return 0;
$arr = array();
if ($handle = opendir($path))
{
while (false !== ($found_dir = readdir($handle)))
{
if ($found_dir !== "." && $found_dir !== ".." && is_dir($path.$found_dir))
{
$arr[count($arr)] = $found_dir;
}
}
}
return $arr;
}
function dir_structure($path,$count,$pre)
{
global $img;
global $dir;
for($i=0;$i<$count;$i++)
$add = $add." ";
$a_dir = sub_dir($path);
for($i=0;$i<count($a_dir);$i++)
{
if($a_dir[$i] == $dir[$count])
{
echo $add.$img."<a href='?dir[]=".$a_dir[$i]."'>".$a_dir[$i]."</a><br>";
dir_structure($path.$a_dir[$i]."/",($count+1),$pre."dir[]=".$a_dir[$i]."&"
}
else
{
echo $add.$img."<a href='?".$pre."dir[]=".$a_dir[$i]."'>".$a_dir[$i]."</a><br>";
}
}
}
dir_structure($root,0,""
?>
My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work