Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Skrypt wyświetlający listę plików.
Mędrzec.
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 10.02.2005

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


Mam taki skrypt
  1. <?
  2. function listDir($dir)
  3. {
  4.  
  5. $dir=getcwd();
  6. $fd=opendir($dir);
  7.  
  8. if(!$fd) return false;
  9. chdir($dir);
  10. while(($file=readdir($fd)) !== false)
  11. {                        
  12.    if($file==&#092;".\") continue;
  13.    if(is_dir($dir.&#092;"\".$file))
  14.    {
  15.       $link=&#092;"<A HREF=lista3.php?\";
  16.       $link.=&#092;"dir=\".dir.\"\".$file.\"\">\".$file.\"</A>\";
  17.       $link.=str_replace(&#092;"\",\"\",$link);
  18.       echo(&#092;"$link\");
  19.    }
  20.    else{
  21.         echo(&#092;"$file\");
  22.        }
  23.       echo(&#092;"<BR>\");
  24. }
  25. closedir($fd);
  26. }
  27.  
  28. @$dir = $_GET['dir'];
  29. if($dir=='') $dir = &#092;".\";
  30. listDir($dir);
  31.  
  32.  ?>

Wyświela on listę plików w danym katalogu, jak jest w nim folder to nie potrafie do niego wejść, poprostu kilkają na folder pokazuje mi się ta sama strona.
Dlaczego tak się dzieje

pozdr.

Ten post edytował Mędrzec. 20.03.2005, 21:20:16
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Nievinny
post
Post #2





Grupa: Zarejestrowani
Postów: 134
Pomógł: 0
Dołączył: 27.01.2005
Skąd: Białystok

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


A kod może być pod PHP5?
Jeśli tak to kod interatora:
  1. <?php
  2.  
  3. class DirectoryTreeInterator extends RecursiveIteratorIterator 
  4. {
  5. public function current() {
  6. return str_repeat( '|&nbsp;&nbsp;', $this->getDepth() ) . '|-' . parent::current();
  7. }
  8. }
  9.  
  10. ?>

Ikod użycia
  1. <?php
  2.  
  3. $Dir = new DirectoryTreeInterator( new RecursiveDirectoryIterator( PATH ), true );
  4. foreach( $Dir as $File ) {
  5. print $File . '<br />';
  6. }
  7.  
  8. define( 'PATH' './' ); //przykladowy katalog do wykonania spisu
  9.  
  10. ?>


I w sumie stałej PATH przypisujesz nazwę katalogu.

Skrypt wyświetla katalogi w postaci drzewa.
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: 26.12.2025 - 13:45