Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Funkcja
xokisx
post
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 28.07.2008

Ostrzeżenie: (0%)
-----


Znalazłem w necie skrypt który wyświetla listy plików z określonego katalogu, oto ten skrypt:
Kod
<?php
  $i = 0;
  $images['file'] = "<img src=\"img/doc.gif\"> ";
  $images['dir'] = "<img align=\"center\" src=\"img/folder.gif\"> ";

  function show_dir($directory)
  {
      global $i, $images;

      $dir = opendir($directory);
      while ( $file = readdir($dir) )
      {
          if ( $file != "." && $file != ".." )
          {
              if ( is_dir($directory."/".$file) )
              {
                  echo ( str_repeat("&nbsp;", $i * 2) . $images['dir'] .  $file . "<br />" );
                  ++$i;
                  show_dir($directory . "/" . $file);
              }
              else
              {
                  echo ( str_repeat("&nbsp;", $i * 3) . $images['file'] . $file . "<br />" );
              }
          }
      }
      closedir($dir);
      --$i;
  }
  show_dir("./../../");
?>

Mógłby mi ktoś przerobić ten skrypt tak aby nie był w postaci funkcji a normalnego kodu ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Kicok
post
Post #2





Grupa: Zarejestrowani
Postów: 1 033
Pomógł: 125
Dołączył: 17.09.2005
Skąd: Żywiec

Ostrzeżenie: (0%)
-----


Cytat("mike")
Pochwal się.

  1. <pre>
  2. <b>c:/usr/</b>
  3. <?php
  4.  
  5. $directiries = array();
  6.  
  7. $directories[0]['dirname'] = 'c:/usr/';
  8. $directories[0]['pointer'] = opendir( 'c:/usr/' );
  9. $level = 1;
  10.  
  11.  
  12. while( true )
  13. {
  14. $file = readdir( $directories[0]['pointer'] );
  15.  
  16. if( !$file )
  17. {
  18. closedir( $directories[0]['pointer'] );
  19. array_shift( $directories );
  20.  
  21. if( !--$level )
  22. {
  23. break;
  24. }
  25. }
  26. elseif( $file != '.' && $file != '..' )
  27. {
  28. echo str_repeat( ' ', $level * 2 ) . $file . "\n";
  29.  
  30. if( is_dir( $directories[0]['dirname'] . $file ) )
  31. {
  32. ++$level;
  33.  
  34. array_unshift( $directories, array() );
  35. $directories[0]['dirname'] = $directories[1]['dirname'] . $file . '/';
  36. $directories[0]['pointer'] = opendir( $directories[0]['dirname'] ); 
  37. }
  38. }
  39. }
  40.  
  41. ?>
  42. </pre>


Proszę. Tablica $directories działa tutaj jak stos ( Nie wiem od której wersji działa "prawdziwy stos" - SPLStack - pewnie 5.3 albo 6.0 )

W sumie zasada działania podobna jak u zimi'ego

Ten post edytował Kicok 28.07.2008, 20:46:45
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 12:22