Jump to content

klaaz

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

klaaz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi there, I am having a problem with my scripting capabilitys. I am trying to write a recursive directory browser wich uses a javascript (great script btw:  [url=http://www.destroydrop.com/javascripts/tree/]dtree[/url]) to display the results. This problem is pure PHP, to get it right I have to feed the javascript like this (simplyfied): d.add(1,0, main directory1); d.add(2,1, first subdir from main directory1); d.add(3,1, second subdir from main directory1); d.add(4,0, main directory2); d.add(5,4, first subdir from main directory2); d.add(6,4, second subdir from main directory2); d.add(7,6, first subdir from second subdir frommain directory 2); and so on. I hope it's obviously that the numbers create the hiĆ«rarchie for dtree here. What I have working so far (displays the first and second level of the directory): [code] <div class="dtree"> <script type="text/javascript"> d = new dTree('d'); d.add(0,-1,'Quartz Quality System'); <? $dir = "testdata/"; if ($handle = opendir($dir)) { $teller = 1; $basis = 0; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (!is_dir($dir.$file)) { echo "d.add($teller,$basis,'$file','#');\n"; } else { $basis2 = $teller; echo "d.add($teller,$basis,'<strong>$file</strong>','#');\n"; $teller++; if ($handle2 = opendir($dir.$file."/")) { while (false !== ($file2 = readdir($handle2))) { if ($file2 != "." && $file2 != "..") { echo "d.add($teller,$basis2,'$file2','#');\n"; $teller++; } } closedir($handle2); } } $teller++; } }   closedir($handle); echo " document.write(d);"; } ?> </script> </div> [/code] Problem with this script is that it does not get all the levels below the selected directory, but instead stops after the second one. I don't want to create each level by hand, because you never know how many levels deep the subdirectories and files will get. I have tried to build in inrecursiveness, but failed. I've read multiple tutorials but they all create array's in PHP, while I need a simple hiĆ«rarchie in numbering the javascript rules. Got a full day of research and trying behind me and definitely need some help now... Somebody genius out there? :)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.