poniższy skrypt wyświetla mi prawidłowo drzewo plików i folderów:

  1. <script type="text/javascript">
  2. function showSubs(topicid)
  3. {
  4. var subs = document.getElementById("folder" + topicid);
  5. if (subs.style.display == "none")
  6. {
  7. subs.style.display = "block";
  8. }
  9. else
  10. {
  11. subs.style.display = "none";
  12. }
  13. }
  14. </script>
  15.  
  16. <?php
  17.  
  18. $listDirCount = 0;
  19.  
  20. function listDir($path = ".")
  21. {
  22. global $listDirCount;
  23. $folders = array();
  24. $files = array();
  25. if ($handle = opendir($path))
  26. {
  27. while (false !== ($file = readdir($handle)))
  28. {
  29. if ($file != "." && $file != "..")
  30. {
  31. if (is_dir($path . "/" . $file))
  32. {
  33. $folders[] = $path . "/" . $file;
  34. }
  35. else
  36. {
  37. $files[] = $file;
  38. }
  39. }
  40. }
  41. for ($i = 0; $i < count($folders); $i++)
  42. {
  43. $listDirCount++;
  44. echo "<a href=\"listing.php\" onclick=\"showSubs($listDirCount)\">" . basename($folders[$i]) . "</a><br/>\n";
  45. echo '<div id="folder' . $listDirCount . '" style="margin-left: 15px; margin-right: 10px; display: none;">';
  46. listDir($folders[$i]);
  47. echo '</div>';
  48. }
  49. for ($i = 0; $i < count($files); $i++)
  50. {
  51. echo "{$files[$i]}<br/>\n";
  52. }
  53. closedir($handle);
  54. }
  55. }
  56.  
  57. listDir();


mam jednak problem z javascript - po kliknięciu na folder powinna mi się wyświetlić zawartość danego folderu, po powtórnym kliknięciu powinien nastąpić powrót. Jednak obecnie po kliknięciu na moment jedynie wyświetla mi się zawartość i zaraz następuje powrót.