Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]bardzo długi skrypt na wyświetlanie katalogów, podkatalogów, podpodkatalogów
Forum PHP.pl > Forum > Przedszkole
Kalysto
Witam. Otóż napisałem dość długi skrypt na przeglądanie katalogów które znajdują się na serwerze. Zapewne nie jest on zbyt funkcjonalny ale w tym jest mój problem:

  1. $dir = ".";
  2. $d = opendir($dir);
  3. while($file = readdir($d)) {
  4. if ($file!="." && $file!=".." && $file!="...") {
  5. echo " <LI><a href='index.php?file=$file'>$file</a></LI>";
  6. }
  7.  
  8.  
  9. if($_GET['file'] == $file){
  10. $dir2 = "$dir/$file";
  11. $d2 = opendir($dir2);
  12. while($file1 = readdir($d2)) {
  13. if ($file1!="." && $file1!=".." && $file1!="...") {
  14. echo " <LI><a href='index.php?file=$file&file2=$file1'>$file1</a></LI>";
  15. }
  16.  
  17.  
  18. if(($_GET['file'] == $file)&($_GET['file2'] == $file1)) {
  19. $dir3 = "$file/$file1";
  20. $d3 = opendir($dir3);
  21. while($file2 = readdir($d3)) {
  22. if ($file2!="." && $file2!=".." && $file2!="...") {
  23. echo " <LI><a href='index.php?file=$file&file2=$file1&file3=$file2'>$file2</a></LI>";
  24. }
  25.  
  26. if(($_GET['file'] == $file)&($_GET['file2'] == $file1)&($_GET['file3'] == $file2)) {
  27. $dir4 = "$file/$file1/$file2/";
  28. $d4 = opendir($dir4);
  29. while($file3 = readdir($d4)) {
  30. if ($file3!="." && $file3!=".." && $file3!="...") {
  31. echo " <LI><a href='index.php?file=$file&file2=$file1&file3=$file2&file4=$file3'>$file3</a></LI>";
  32. }
  33.  
  34. closedir($dir4);
  35. }
  36. }
  37.  
  38. closedir($dir3);
  39. }
  40. }
  41.  
  42.  
  43. closedir($dir2);
  44. }
  45. }
  46. closedir($dir);
  47. }
  48.  


Czy jest jakiś sposób by ten skrypt skrócić z 4 (gdyby były podfoldery jeszcze to zapewne było by więcej) dirów, opendirów itd.. do mniejszej ilości? Jakoś zapętlenia tego?
I zrobienie by gdy dotrę już do właściwego pliku mógłbym go pobrać? Proszę o pomoc bo sam się już w tym skrypcie zgubiłem.
redeemer
http://php.net/manual/en/class.recursivedi...oryiterator.php

Zobacz sobie przykłady w User Contributed Notes
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.