So, basicly, the issue that i have is that i do a readdir(), but i'm getting all sorted by name, and i need it sorted by type... It was working fine, i don't know what i've changed.
The code is splitted in two functions and a call.
The function to read the dir is:
function get_dir_files($dir){
$folders_files = array();
if($handle = opendir($dir)){
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".."){
if(is_dir($dir. "/" .$file)){
$folders_files["$file"] = get_dir_files($dir. '/' .$file);
}else{
$folders_files[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $folders_files;
}
The other function, makes a list of all those arrays:
function show_dir_files($folders_files, $path=""){
foreach($folders_files as $key => $value){
if(is_string($key)){
echo '<li style="list-style-type: disc">';
echo $key;
echo '<ul>';
show_dir_files($value, $path.$key.'/');
echo "</ul></li>";
}else{
echo '<li style="list-style-type: circle">';
echo '<a href="'.$path.$value.' " target="_blank">' .$value. '</a>';
echo "</li>";
}
}
}
And i just have to do this call that does all the work:
show_dir_files(get_dir_files($root), $root);
It's all working fine with my arrays. The only problem is that it was sorted by type, but i don't know what i did and started to show sorted by name..
Thanks for the help :).


Sign In
Create Account

Guest_GerarD_91_*
Back to top









