login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Handige scripts > Directory Indexer

Directory Indexer

Auteur: XenoX - 21 april 2005 - 17:17 - Gekeurd door: Joel - Hits: 10945 - Aantal punten: 4.85 (10 stemmen)




Dit script vervangt die saaie indexen van apache en vervangt ze door een mooiere en duidelijkere indexer.

Zet dit script in een directory en hij doet het werk.

Code:
index.php
  1. <?php
  2.  
  3. if(IsSet($_GET['i']))
  4. {
  5. $i = trim($_GET['i']);
  6.  
  7. $img['img'] = "R0lGODlhEAAQAPcAAP//////AP8A//8AAAD//wD/AAAA/wAAAPuBhP0RI7Crrr24vL25vn+CmJ6syZ6rxbfF4cbO3srO1oOk4WF4oo6fvpyuzqCvyqKxzKGwy6i30qa10KKxy6Oxy6Kwyb3M57G/2JyovqCswsTR6dDd9crW7NPe8tXg89Hb7uLs/uLr/Njh8eHp9wBe9YaZuYiauYeYtZWmw5mqxqCvyKi30KSyysXW8p+rvqu3ysPQ5tvo/eDr/dzm9uLs/OTt/Njg7eDn8+vy/gxn7Ku92LvO68TQ4uPu/t7p+c/Y5tXe7Nfg7cvb8ejw++vw9+fs87LD2OHu/lem/vH3/lSp/uTx/vP5/snj9+33/qGoqPz+/v3+/lXSYAC1AH3GdS6qHnDIW1OmL+Hp173JqoGaKby9srurRv3slf7dbf7cc/7Xb/7QZ/3SdP7FVd6wUP7LaP6/SP68SeS7cv6vMP62QNycN+CoTN2nTfvt1fueGf6qL/6vN/6xOf65V+C/jP2XEv6eGvmeH/6gI/6iJOCSKM+WR9OZSvjEff6ZG8mCKrB/RNifWv2EAPeAAf6IAuR5BP6JCP6QEMuMSNKTTeC7kbBhEKxdEL9rFqlfFa5iGMR0I45aJsuQVNikcNuugNG8pvLk1v17AO1zAKlUBq5XCL5kE7NiFqBdHplZHrVuLr97PcB/Q690PbF9T9CYY9KujN25l6NJAJtKA5JFBIZKF5NnQcqcdKaGbLVQAKpKAJA/ALGReKuQe+dXBa+ZjKuSh/BvO/55QcY0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JgALLhwnIAABjY6NJQAKLxsnHQADmZqZJAAJLxknGgAFpaalIwAILxcnFgAGsbKxIgAHLilbERAPDg0MCwoJCAcwLTErLS/LzM0vLStCKSrU1dYqQkEAOw==";
  11. $img['<x>'] = "R0lGODlhDQAQANUAAL60urm203d3wXd3wMHB2sTG4ra5xL/K2MHO2b/N1bzM1MHP1r/O1b7N1LbKzrvN0L7Q0ZacnHh8fLq+vp6hoYqMjLu9vX1+fmRlZfz9/ez19MHIx/H49+n08uz29Ov18/f7+tS/SqGBObmXSZBqMIZoQZ2CXKmQbryqkZJ7YY14boRtbP///8fHx5eXl5OTk4mJiYODg3Z2dnBwcGlpaWBgYP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAADYALAAAAAANABAAAAZyQJtwSCyOQiRRKBVamVpCgkBAQqkCJ4DJJRwUSp2SpwQqsWbdR2ft4YAy5+5i3Wm/47YBo3PpW+5oeQl0dnCBAxB8fRcWLHgDDYRuhl0Hin6OhwiSgF0KfBaFjw5rHxobExQVMEMGERIYNTQyMS9Ft0RBADs=";
  12. $img['rar'] = &$img['zip'];
  13. $img['tar'] = &$img['zip'];
  14. $img['html'] = &$img['htm'];
  15. $img['php'] = &$img['htm'];
  16. $img['asp'] = &$img['htm'];
  17. $img['jpg'] = &$img['img'];
  18. $img['gif'] = &$img['img'];
  19. $img['png'] = &$img['img'];
  20. $img['bmp'] = &$img['img'];
  21.  
  22. if(IsSet($img[$i]))
  23. {
  24. $d = &$img[$i];
  25. }
  26. else
  27. {
  28. $d = &$img['<x>'];
  29. }
  30.  
  31. header('Content-type: image/gif');
  32. header('Content-Disposition: attachment; filename="' . $i . '"');
  33.  
  34.  
  35. }
  36.  
  37. function getExt($filename)
  38. {
  39. $atemp = explode('.', $filename);
  40.  
  41. return strtolower($atemp[sizeof($atemp) - 1]);
  42. }
  43.  
  44. function size($size)
  45. {
  46. $mult = 'kB';
  47. $prec = 0;
  48. if(round($size / 1024, 0))
  49. {
  50. $size /= 1024;
  51. $mult = 'kB';
  52. $prec = 3;
  53. }
  54. if(round($size / 1024, 0))
  55. {
  56. $size /= 1024;
  57. $mult = 'mB';
  58. $prec = 3;
  59. }
  60.  
  61. return (round($size, $prec) . ' ' . $mult);
  62. }
  63.  
  64. function fsize($sfile)
  65. {
  66. return filesize($sfile);
  67. }
  68.  
  69. function dsize($sdir)
  70. {
  71. $size = 0;
  72.  
  73. $handle = opendir($sdir);
  74. while(false !== ($read = readdir($handle)))
  75. {
  76. if($read <> '.' && $read <> '..')
  77. {
  78. if(is_file($sdir . $read))
  79. {
  80. $size += fsize($sdir . $read);
  81. }
  82. elseif(is_dir($sdir . $read))
  83. {
  84. $size += dsize($sdir . $read . '/');
  85. }
  86. }
  87. }
  88.  
  89. return $size;
  90. }
  91.  
  92. if(IsSet($_GET['dir']) && $_GET['dir'] <> '' && is_dir($_GET['dir']))
  93. {
  94. if($_GET['dir'] == './')
  95. {
  96. $dir = $_GET['dir'];
  97. }
  98. elseif(eregi('\.\./', $_GET['dir']))
  99. {
  100. $dir = './';
  101. }
  102. else
  103. {
  104. if(substr($_GET['dir'], -1) == '/')
  105. {
  106. $dir = $_GET['dir'];
  107. }
  108. else
  109. {
  110. $dir = $_GET['dir'] . '/';
  111. }
  112. }
  113. } else {
  114. $dir = './';
  115. }
  116.  
  117. if($dir == './')
  118. {
  119. $cur_dir = 'Root';
  120. }
  121. else
  122. {
  123. $ex = explode('/', $dir);
  124. array_pop($ex);
  125. $cur_dir = ucwords(array_pop($ex));
  126. }
  127.  
  128. $handle = opendir($dir);
  129. while(false !== ($read = readdir($handle)))
  130. {
  131. if($read <> '.' && $read <> '..')
  132. {
  133. $show[] = $read;
  134. }
  135. }
  136. ?>
  137. <html>
  138.  
  139. <head>
  140. <title>Directory Indexer</title>
  141.  
  142. <style>
  143. body { margin: 0px; }
  144. body, td, th { font-family: Arial; font-size: 12px; }
  145. a { color: #000000; text-decoration: underline; }
  146. a:hover { color: #666666; text-decoration: none; }
  147. .dir_container { border-left: 1px solid #000000; border-right: 1px solid #000000; width: 760px; }
  148. .dir_container h1 { margin: 10px; }
  149. .dir_container th { background-color: #000000; color: #FFFFFF; text-align: left; }
  150. .row1 { background-color: #FFFFFF; }
  151. .row2 { background-color: #DDDDDD; }
  152. .error { background-color: #F2DDDD; border: 1px solid #992A2A; border-top: 0px; font-family: Verdana; margin: 5px; padding: 0px; }
  153. .error h4 { background-color: #E3C0C0; border: 1px solid #992A2A; border-left: 0px; border-right: 0px; font-family: Verdana; color: #992A2A; font-size: 12px; font-weight: bold; margin: 0px; padding: 5px; }
  154. .error p { background-color: transparent; border: 0px; font-family: Verdana; color: #992A2A; font-size: 12px; margin: 0px; padding: 8px; }
  155. </style>
  156. </head>
  157.  
  158. <body>
  159.  
  160. <div align="center">
  161. <table border="0" cellpadding="5" cellspacing="0" class="dir_container">
  162. <tr>
  163. <td colspan="5">
  164. <h1><?php echo $cur_dir; ?></h1>
  165.  
  166. <?php
  167. if($dir <> './')
  168. {
  169. $ex = substr($dir, 2, -1);
  170. $ex = explode('/', $ex);
  171. array_pop($ex);
  172.  
  173. $dirs = '<a href="index.php?dir=./">Root</a> / ';
  174. foreach($ex as $nr => $tdir)
  175. {
  176. $link = './';
  177. for($i = 0; $i < $nr; $i++)
  178. {
  179. $link .= $ex[$i] . '/';
  180. }
  181.  
  182. $dirs .= '<a href="index.php?dir=' . $link . $tdir . '">' . $tdir . '</a> / ';
  183. }
  184.  
  185. echo $dirs;
  186. }
  187. ?>
  188. </td>
  189. </tr>
  190. <tr>
  191. <th width="1%"></th>
  192. <th>Naam:</th>
  193. <th width="15%">Grootte:</th>
  194. <th width="20%">Type:</th>
  195. <th width="30%">Gewijzigd op:</th>
  196. </tr>
  197. <?php
  198. if(IsSet($show))
  199. {
  200. $i = 0;
  201. foreach($show as $row)
  202. {
  203. $tr_class = ($i % 2 ? 'row1' : 'row2');
  204. ?>
  205. <tr class="<?php echo $tr_class; ?>">
  206. <td><img src="index.php?i=<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>" alt="<?php echo $row; ?>"></td>
  207. <td><a href="<?php echo (is_dir($dir . $row) ? 'index.php?dir=' . $dir . $row : $dir . $row); ?>"><?php echo $row; ?></a></td>
  208. <td align="right"><?php echo size(is_dir($dir . $row) ? dsize($dir . $row . '/') : fsize($dir . $row)); ?></td>
  209. <td><?php echo (is_dir($dir . $row) ? 'Bestandsmap' : getExt($row) . ' bestand'); ?></td>
  210. <td><?php echo date('F d Y H:i:s', filectime($dir . $row)); ?></td>
  211. </tr>
  212. <?php
  213. $i++;
  214. }
  215. }
  216. else
  217. {
  218. ?>
  219. <tr>
  220. <td colspan="5"><div class="error"><h4>Directory is leeg</h4> <p>Er staan (nog) geen mappen en/of bestanden in deze directory.</p></div></td>
  221. </tr>
  222. <?php
  223. }
  224. ?>
  225. </table>
  226. </div>
  227.  
  228. </body>
  229.  
  230. </html>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (19)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.049s