PageRenderTime 52ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/php/directorylisting/DirectoryListing.php

https://github.com/kaartine/Rysty
PHP | 244 lines | 159 code | 17 blank | 68 comment | 42 complexity | e32088b0bd4b83d608e95d2228f08951 MD5 | raw file
  1. <?php
  2. ########################################################
  3. # Script Info
  4. # ===========
  5. # File: DirectoryListing.php
  6. # Author: Ash Young (ash@evoluted.net
  7. # Created: 20/12/03
  8. # Modified: 27/09/04
  9. # Website: http://evoluted.net/directorylisting.php
  10. # Requirements: PHP
  11. #
  12. # Description
  13. # ===========
  14. # Displays all files contained within a directory in
  15. # a well formed table, with category-image tags
  16. #
  17. # If you have any functions that you like to see
  18. # implemented in this script then please just send
  19. # an email to ash@evoluted.net
  20. #
  21. # Useage
  22. # ======
  23. #
  24. # To change the colours display when using the script
  25. # scroll down to set up section
  26. #
  27. # To use the script just upload to your server with
  28. # the images and point your browser to the scripts
  29. # filename
  30. #
  31. # SETUP
  32. # =====
  33. #
  34. # Change the following variables to display what colours
  35. # the script outputs
  36. ########################################################
  37. error_reporting(null);
  38. DEFINE("IMAGEROOT", "kuvat/images/"); #CHANGE /images/ TO THE PATH OF THE ASSOCIATED IMAGES
  39. // name of folder, no starting / or ending / relative to index.php file
  40. $HOMEDIR="intranet";
  41. $HOMEDIR="./".$HOMEDIR."/";
  42. $textcolor = "#FFFFFF"; #TEXT COLOUR
  43. $bgcolor = "#535353"; #PAGE BACKGROUND COLOUR
  44. $normalcolor = "#0066FF"; #TABLE ROW BACKGROUND COLOUR
  45. $highlightcolor = "#006699"; #TABLE ROW BACKGROUND COLOUR WHEN HIGHLIGHTED
  46. $headercolor = "#003366"; #TABLE HEADER BACKGROUND COLOUR
  47. $bordercolor = "#202750"; #TABLE BORDER COLOUR
  48. /*
  49. <html>
  50. <head>
  51. <title>Directory Listings of <? echo $_SERVER["REQUEST_URI"]; ?> </title>
  52. <style type='text/css'>
  53. <!--
  54. body { color: <? echo $textcolor; ?>; font: tahoma, small verdana,arial,helvetica,sans-serif; background-color: <? echo $bgcolor; ?>; }
  55. table { font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; border: 1px; border-style: solid; border-color: <? echo $bordercolor; ?>; }
  56. .row { background-color: <? echo $normalcolor; ?>; border: 0px;}
  57. a:link { color: <? echo $textcolor; ?>; text-decoration: none; }
  58. a:visited { color: <? echo $textcolor; ?>; text-decoration: none; }
  59. a:hover, a:active { color: <? echo $textcolor; ?>; text-decoration: none; }
  60. img {border: 0;}
  61. #bottomborder {border: <? echo $bordercolor;?>;border-style: solid;border-top-width: 0px;border-right-width: 0px;border-bottom-width: 1px;border-left-width: 0px}
  62. .copy { text-align: center; color: <? echo $textcolor; ?>; font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; text-decoration: underline; }
  63. //-->
  64. </style>
  65. </head>
  66. <body>
  67. */
  68. $files=array();
  69. $dirs=array();
  70. $tm = TranslationManager::instance();
  71. clearstatcache();
  72. $curDir = $HOMEDIR;
  73. if ( isset($_REQUEST['directory'] ) ) {
  74. $path_parts = pathinfo($_REQUEST['directory']);
  75. //echo "$path_parts[basename]";
  76. /*echo $path_parts['dirname'], "<br>\n";
  77. echo $path_parts['basename'], "<br>\n";
  78. //echo $path_parts['extension'], "<br>\n";
  79. */
  80. if ( substr_count($path_parts['dirname']."/",$HOMEDIR ) == 1 and
  81. substr_count($path_parts['dirname']."/","../" ) == 0 // no path altering
  82. and $path_parts['basename'] != ".." ) { // double check
  83. $curDir = $path_parts['dirname']."/".$path_parts['basename']."/";
  84. }
  85. }
  86. $PHP_SELF = basename(__FILE__);
  87. if ($handle = opendir($curDir)) {
  88. while (false !== ($file = readdir($handle))) {
  89. if ($file != "." && $file != substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {
  90. if ( $file == ".." and $curDir == $HOMEDIR) {
  91. continue;
  92. }
  93. if (filetype($curDir.$file) == "dir") {
  94. //SET THE KEY ENABLING US TO SORT
  95. $n++;
  96. if($_REQUEST['sort']=="date") {
  97. $key = filemtime($curDir.$file) . ".$n";
  98. }
  99. else {
  100. $key = $n;
  101. }
  102. $dirs[$key] = $file . "/";
  103. }
  104. else {
  105. //SET THE KEY ENABLING US TO SORT
  106. $n++;
  107. if($_REQUEST['sort']=="date") {
  108. $key = filemtime($curDir.$file) . ".$n";
  109. }
  110. elseif($_REQUEST['sort']=="size") {
  111. $key = filesize($curDir.$file) . ".$n";
  112. }
  113. else {
  114. $key = $n;
  115. }
  116. $files[$key] = $file;
  117. }
  118. }
  119. }
  120. closedir($handle);
  121. }
  122. #USE THE CORRECT ALGORITHM AND SORT OUR ARRAY
  123. if($_REQUEST['sort']=="date") {
  124. @ksort($dirs, SORT_NUMERIC);
  125. @ksort($files, SORT_NUMERIC);
  126. }
  127. elseif($_REQUEST['sort']=="size") {
  128. @natcasesort($dirs);
  129. @ksort($files, SORT_NUMERIC);
  130. }
  131. else {
  132. @natcasesort($dirs);
  133. @natcasesort($files);
  134. }
  135. #ORDER ACCORDING TO ASCENDING OR DESCENDING AS REQUESTED
  136. if($_REQUEST['order']=="desc" && $_REQUEST['sort']!="size") {$dirs = array_reverse($dirs);}
  137. if($_REQUEST['order']=="desc") {$files = array_reverse($files);}
  138. $dirs = @array_values($dirs); $files = @array_values($files);
  139. $LINKNAME = $_SERVER['PHP_SELF']."?toiminto=intranet&directory=".$curDir."&";
  140. echo $tm->getText("Hakemisto").": ".$curDir;
  141. echo "<table width=\"450\" border=\"0\" cellspacing=\"0\" align=\"center\"><tr bgcolor=\"$headercolor\"><td colspan=\"2\" id=\"bottomborder\">";
  142. if($_REQUEST['sort']!="name") {
  143. echo "<a href=\"".$LINKNAME."sort=name&order=asc\">\n";
  144. }
  145. else {
  146. if($_REQUEST['order']=="desc") {
  147. echo "<a href=\"".$LINKNAME."sort=name&order=asc\">\n";
  148. }
  149. else {
  150. echo "<a href=\"".$LINKNAME."sort=name&order=desc\">\n";
  151. }
  152. }
  153. echo $tm->getText("Tiedosto")."</td><td id=\"bottomborder\" width=\"50\"></a>\n";
  154. if($_REQUEST['sort']!="size") {
  155. echo "<a href=\"".$LINKNAME."sort=size&order=asc\">\n";
  156. }
  157. else {
  158. if($_REQUEST['order']=="desc") {#
  159. echo "<a href=\"".$LINKNAME."sort=size&order=asc\">\n";
  160. }
  161. else {
  162. echo "<a href=\"".$LINKNAME."sort=size&order=desc\">\n";
  163. }
  164. }
  165. echo $tm->getText("Koko")."</td><td id=\"bottomborder\" width=\"120\" nowrap></a>\n";
  166. if($_REQUEST['sort']!="date") {
  167. echo "<a href=\"".$LINKNAME."sort=date&order=asc\">\n";
  168. }
  169. else {
  170. if($_REQUEST['order']=="desc") {#
  171. echo "<a href=\"".$LINKNAME."sort=date&order=asc\">\n";
  172. }
  173. else {
  174. echo "<a href=\"".$LINKNAME."sort=date&order=desc\">\n";
  175. }
  176. }
  177. echo $tm->getText("Muokattu")."</a></td></tr>\n";
  178. foreach ($dirs as $k => $v) {
  179. if ( substr( $v,-3) == "../") {
  180. $folderLink = $_SERVER['PHP_SELF']."?toiminto=intranet&directory=".$path_parts['dirname']."/";
  181. }
  182. else {
  183. $folderLink = $_SERVER['PHP_SELF']."?toiminto=intranet&directory=".$curDir.$v ;
  184. }
  185. echo "\t<tr class=\"row\" onMouseOver=\"this.style.backgroundColor='$highlightcolor'; this.style.cursor='hand';\" onMouseOut=\"this.style.backgroundColor='$normalcolor';\" onClick=\"window.location.href='" .$folderLink. "';\">";
  186. echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "folder.gif\" width=\"16\" height=\"16\" alt=\"Directory\"></td>";
  187. echo "\t\t<td><a href=\"".$folderLink."\">" . $v . "</a></td>";
  188. echo "\t\t<td width=\"50\" align=\"left\">-</td>";
  189. echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($curDir.$v)) . "</td>";
  190. echo "\t</tr>\n";
  191. }
  192. foreach ($files as $k => $v) {
  193. switch (substr($v, -3)) {
  194. case "jpg":
  195. $img = "jpg.gif";
  196. break;
  197. case "gif":
  198. $img = "gif.gif";
  199. break;
  200. case "zip":
  201. $img = "zip.gif";
  202. break;
  203. case "png":
  204. $img = "png.gif";
  205. break;
  206. case "avi":
  207. $img = "move.gif";
  208. break;
  209. case "mpg":
  210. $img = "move.gif";
  211. break;
  212. default:
  213. $img = "what.gif";
  214. break;
  215. }
  216. echo "\t<tr class=\"row\" onMouseOver=\"this.style.backgroundColor='$highlightcolor'; this.style.cursor='hand';\" onMouseOut=\"this.style.backgroundColor='$normalcolor';\" onClick=\"window.location.href='" . $curDir.$v . "';\">\r\n";
  217. echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "$img\" width=\"16\" height=\"16\" alt=\"Directory\"></td>\r\n";
  218. echo "\t\t<td><a href=\"" . $curDir.$v . "\">" . $v . "</a></td>\r\n";
  219. echo "\t\t<td width=\"50\" align=\"left\">" . round(filesize($curDir.$v)/1024) . "KB</td>\r\n";
  220. echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($curDir.$v)) . "</td>\r\n";
  221. echo "\t</tr>\r\n";
  222. }
  223. echo "</table>\n<div align=\"center\"><a href=\"http://evoluted.net/directorylisting.php\" class=\"copy\">Directory Listing Script</a>. <a href=\"http://evoluted.net/\" class=\"copy\">&copy 2003-2004 Ash Young</a></div>\n";
  224. /*</body>
  225. </html>
  226. */
  227. ?>