Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem ze skryptem generującym drzewko katalogów.
miedzna
post 7.06.2006, 11:31:49
Post #1





Grupa: Zarejestrowani
Postów: 401
Pomógł: 1
Dołączył: 10.03.2004
Skąd: Warszawa

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


Mam taki kod:
  1. <?php
  2. // Show size of each file, 1 for YES, 0 for NO
  3. $showsize = 1;
  4.  
  5. // Array with file types to display and the images to use.
  6. // Syntax: $display['filetype'] = "image";
  7. $display['php'] = "php.gif";
  8. $display['html'] = "html.gif";
  9. $display['htm'] = "html.gif";
  10. $display['shtml'] = "html.gif";
  11.  
  12. // Array with directories to exclude.
  13. // Syntax: $excludedir[] = "directory";
  14. $excludedir[] = "cgi-bin";
  15. $excludedir[] = "images";
  16. $excludedir[] = "realaudio";
  17. $excludedir[] = "style";
  18.  
  19. // Array with files to exclude.
  20. // Syntax: $excludefile[] = "filename";
  21. $excludefile[] = "phpinfo.php";
  22.  
  23. $stime = gettimeofday();
  24.  
  25. // Set some important stuff
  26. $root = getcwd();
  27.  
  28. $pre = explode("/", $_SERVER['REQUEST_URI']);
  29. array_pop($pre);
  30. $prefix = join("/", $pre);
  31.  
  32. // Uncomment the 2 lines below to create a tree of all files and directories on 
  33. // your webserver if the script is in a subdirectory
  34. $root = str_replace($prefix, "", $root);
  35. $prefix = "";
  36.  
  37. $root .= "/";
  38.  
  39. // Display server name and directory
  40. echo "<table width="80%" class="sitemap_tag2" ellspacing="0" cellpadding="0" border="0">n";
  41. echo "<tr><td><img align="absmiddle" src="server.gif" border="0"> <b>http://".$_SERVER['SERVER_NAME'];
  42. echo "$prefix/";
  43. echo "</b></td></tr><tr><td><img align="absmiddle" src="vertical.gif" border="0"></td></tr>n";
  44.  
  45. function get_extension($name) {
  46. $array = explode(".", $name);
  47. $retval = strtolower(array_pop($array));
  48. return $retval;
  49. }
  50.  
  51. // Recursion! And away we go...
  52. // Set some globals and clean up a bit...
  53. // What a pig...
  54. function list_dir($chdir) {
  55. global $root, $prefix, $showsize, $display, $excludedir, $excludefile;
  56. unset($sdirs);
  57. unset($sfiles);
  58. chdir($chdir);
  59. $self = basename($_SERVER['PHP_SELF']);
  60.  
  61. // Open the current directory
  62. $handle = opendir('.');
  63. // Read directory. If the item is a directory, place it in $sdirs.
  64. // If it's a filetype we want, put it in $sfiles */
  65. while ($file = readdir($handle))
  66. {
  67. if(is_dir($file) && $file != "." && $file != ".." && !in_array($file, $excludedir))
  68. { $sdirs[] = $file; }
  69. elseif(is_file($file) && $file != "$self" && array_key_exists(get_extension($file), $display)
  70. && !in_array($file, $excludefile))
  71. { $sfiles[] = $file; }
  72. }
  73.  
  74. // Count the slashes to determine how deep we're in the directory.
  75. // Add lines to make it pretty.
  76. $dir = getcwd();
  77. $dir1 = str_replace($root, "", $dir."/");
  78. $count = substr_count($dir1, "/") + substr_count($dir1, "");
  79.  
  80. // Display directory names and recursively list them.
  81. if(is_array($sdirs)) {
  82. sort($sdirs);
  83. reset($sdirs);
  84.  
  85. for($y=0; $y<sizeof($sdirs); $y++) {
  86. echo "<tr><td>";
  87. for($z=1; $z<=$count; $z++)
  88. { echo "<img align="absmiddle" src="vertical.gif" border="0">&nbsp;&nbsp;&nbsp;"; }
  89. if(is_array($sfiles))
  90. { echo "<img align="absmiddle" src="verhor.gif" border="0">"; }
  91. else
  92. { echo "<img align="absmiddle" src="verhor1.gif" border="0">"; }
  93. echo "<img align="absmiddle" src="folder.gif" border="0"> <B>$sdirs[$y]</B>";
  94. list_dir($dir."/".$sdirs[$y]);
  95. }
  96. }
  97.  
  98. chdir($chdir);
  99.  
  100. // Run through the array of files and show them.
  101. if(is_array($sfiles)) {
  102. sort($sfiles);
  103. reset($sfiles);
  104.  
  105. $sizeof = sizeof($sfiles);
  106.  
  107. // What file types shall we display?
  108. for($y=0; $y<$sizeof; $y++) {
  109. echo "<tr><td>";
  110. for($z=1; $z<=$count; $z++)
  111. { echo "<img align="absmiddle" src="vertical.gif" border="0">&nbsp;&nbsp;&nbsp;"; }
  112. if($y == ($sizeof -1))
  113. { echo "<img align="absmiddle" src="verhor1.gif" border="0">"; }
  114. else
  115. { echo "<img align="absmiddle" src="verhor.gif" border="0">"; }
  116. echo "<img align="absmiddle" src="";
  117. echo $display[get_extension($sfiles[$y])];
  118. echo "" border="0"> ";
  119.  
  120. // pokazuje pliki
  121. echo "<a href="".$HTTP_REFERER."$prefix/$dir1$sfiles[$y]" target="_new">$sfiles[$y]</a>";
  122. if($showsize) {
  123. $fsize = @filesize($sfiles[$y])/1024;
  124. printf(" (%.2f kB)", $fsize);
  125. }
  126. echo "</td></tr>";
  127.  
  128. }
  129. echo "<tr><td>";
  130. for($z=1; $z<=$count; $z++)
  131. { echo "<img align="absmiddle" src="vertical.gif" border="0">&nbsp;&nbsp;&nbsp;"; }
  132. echo "</td></tr>n"; 
  133. }
  134. }
  135.  
  136. list_dir($root);
  137.  
  138. echo "</table><br>n";
  139.  
  140. // How long did that take?
  141. $ftime = gettimeofday();
  142. $time = round(($ftime[sec] + $ftime[usec] / 1000000) - ($stime[sec] + $stime[usec] / 1000000), 5);
  143. echo "<div align="center" class="sitemap_tag2">This page was generated in $time seconds.</div>n";
  144. ?>


ładnie pokazywana jest cała struktura katalogó+podkatalogów+plików, ale problem jest taki, że np. przy plikach link jest generowany tak:
http://localhost/z:/home/localhost/www/fol...folder/plik.php

gdzie to można zmienić?
Go to the top of the page
+Quote Post
dr_bonzo
post 8.06.2006, 07:59:18
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


To jest twoj skrypt (to przeniose) czy jakis gotowiec (to podaj jego nazwe)?


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
em1X
post 8.06.2006, 09:36:21
Post #3





Grupa: Zarejestrowani
Postów: 984
Pomógł: 41
Dołączył: 16.03.2002
Skąd: Płock

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


jestem ciekaw jak mamy obejrzec wynik twojego skryptu kiedy podałeś adres swojego hosta lokalnego? laugh.gif


--------------------
eh, co polska wódka to polska wódka
Go to the top of the page
+Quote Post
miedzna
post 9.06.2006, 11:34:36
Post #4





Grupa: Zarejestrowani
Postów: 401
Pomógł: 1
Dołączył: 10.03.2004
Skąd: Warszawa

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


Ludzie, przecie pisze ze link jest generowany taki i siaki, nie podawalem linkow zebyscie sobie lukneli na wynik. Tylko podalem przyklad linku i oczekuje, ze ktos, KTO SIE ZNA luknie na kod i powie gdzie jest blad...
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 09:52