Guest User

Untitled

a guest
Jan 12th, 2018
488
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!doctype html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="UTF-8">
  6. <title>Directory Contents</title>
  7. <style type="text/css">
  8. thead{
  9. background-color: orangered;
  10. color:white;
  11. }
  12. thead tr th{
  13. padding: 10px;
  14. }
  15. table {
  16. border-collapse: collapse;
  17. border-spacing: 0;
  18. }
  19. td{
  20. padding: 10px;
  21. }
  22.  
  23.  
  24. * {
  25. padding:0;
  26. margin:0;
  27. }
  28.  
  29. body {
  30. color: #333;
  31. font: 14px Sans-Serif;
  32. padding: 50px;
  33. background: #eee;
  34. }
  35.  
  36. h1 {
  37. text-align: center;
  38. padding: 20px 0 12px 0;
  39. margin: 0;
  40. }
  41. h2 {
  42. font-size: 16px;
  43. text-align: center;
  44. padding: 0 0 12px 0;
  45. }
  46.  
  47. #container {
  48. box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
  49. position: relative;
  50. background: white;
  51. }
  52.  
  53. table {
  54. background-color: #F3F3F3;
  55. border-collapse: collapse;
  56. width: 100%;
  57. margin: 15px 0;
  58. }
  59.  
  60. th {
  61. background-color: #FE4902;
  62. color: #FFF;
  63. cursor: pointer;
  64. padding: 5px 10px;
  65. }
  66.  
  67. th small {
  68. font-size: 9px;
  69. }
  70.  
  71. td, th {
  72. text-align: left;
  73. }
  74.  
  75. a {
  76. text-decoration: none;
  77. }
  78.  
  79. td a {
  80. color: #663300;
  81. display: block;
  82. padding: 5px 10px;
  83. }
  84. th a {
  85. padding-left: 0
  86. }
  87.  
  88. td:first-of-type a {
  89. padding-left: 35px;
  90. }
  91. th:first-of-type {
  92. padding-left: 35px;
  93. }
  94.  
  95. td:not(:first-of-type) a {
  96. background-image: none !important;
  97. }
  98.  
  99. tr:nth-of-type(odd) {
  100. background-color: #E6E6E6;
  101. }
  102.  
  103. tr:hover td {
  104. background-color:#CACACA;
  105. }
  106.  
  107. tr:hover td a {
  108. color: #000;
  109. }
  110. </style>
  111.  
  112. </head>
  113.  
  114. <body>
  115.  
  116. <div id="container">
  117.  
  118. <h1>Directory Contents</h1>
  119.  
  120. <table class="sortable">
  121. <thead>
  122. <tr>
  123. <th></th>
  124. <th>Filename</th>
  125. <th>Type</th>
  126. <th>Size <small>(bytes)</small></th>
  127. <th>Date Modified</th>
  128. <th></th>
  129. </tr>
  130. </thead>
  131. <tbody>
  132. <?php
  133. // Opens directory
  134. $directory ="images1/";
  135. $myDirectory=opendir($directory);
  136.  
  137. // Gets each entry
  138. while($entryName=readdir($myDirectory)) {
  139. $dirArray[]=$entryName;
  140. }
  141.  
  142. // Finds extensions of files
  143. function findexts ($filename) {
  144. $filename=strtolower($filename);
  145. $exts = pathinfo($filename, PATHINFO_EXTENSION);
  146. //$exts=split("[.]", $filename);
  147. $n=count($exts)-1;
  148. $exts=$exts[$n];
  149. return $exts;
  150. }
  151.  
  152. // Closes directory
  153. closedir($myDirectory);
  154.  
  155. // Counts elements in array
  156. $indexCount=count($dirArray);
  157.  
  158. // Sorts files
  159. sort($dirArray);
  160.  
  161. // Loops through the array of files
  162. for($index=0; $index < $indexCount; $index++) {
  163.  
  164. // Allows ./?hidden to show hidden files
  165. if($_SERVER['QUERY_STRING']=="hidden"){
  166. $hide="";
  167. $ahref="./";
  168. $atext="Hide";}
  169. else{
  170. $hide=".";
  171. $ahref="./?hidden";
  172. $atext="Show";}
  173. if(substr("$dirArray[$index]", 0, 1) != $hide) {
  174.  
  175. // Gets File Names
  176. $name=$dirArray[$index];
  177. $namehref=$dirArray[$index];
  178.  
  179. // Gets Extensions
  180. $extn = findexts($dirArray[$index]);
  181.  
  182. // Gets file size
  183. $size = number_format(filesize($directory.$dirArray[$index]));
  184.  
  185. // Gets Date Modified Data
  186. $modtime=date("d/m/y g:i a", filemtime($directory.$dirArray[$index]));
  187. $timekey=date("YmdHis", filemtime($directory.$dirArray[$index]));
  188.  
  189. // Prettifies File Types, add more to suit your needs.
  190. switch ($extn){
  191. case "png": $extn="PNG Image"; break;
  192. case "jpg": $extn="JPEG Image"; break;
  193. case "svg": $extn="SVG Image"; break;
  194. case "gif": $extn="GIF Image"; break;
  195. case "ico": $extn="Windows Icon"; break;
  196.  
  197. case "txt": $extn="Text File"; break;
  198. case "log": $extn="Log File"; break;
  199. case "htm": $extn="HTML File"; break;
  200. case "php": $extn="PHP Script"; break;
  201. case "js": $extn="Javascript"; break;
  202. case "css": $extn="Stylesheet"; break;
  203. case "pdf": $extn="PDF Document"; break;
  204.  
  205. case "zip": $extn="ZIP Archive"; break;
  206. case "bak": $extn="Backup File"; break;
  207.  
  208. default: $extn=strtoupper($extn)." File"; break;
  209. }
  210.  
  211. // Separates directories
  212. if(is_dir($dirArray[$index])) {
  213. $extn="&lt;Directory&gt;";
  214. $size="&lt;Directory&gt;";
  215. $class="dir";
  216. } else {
  217. $class="file";
  218. }
  219.  
  220. // Cleans up . and .. directories
  221. if($name=="."){$name=". (Current Directory)"; $extn="&lt;System Dir&gt;";}
  222. if($name==".."){$name=".. (Parent Directory)"; $extn="&lt;System Dir&gt;";}
  223.  
  224. // Print 'em
  225. print("
  226. <tr class='$class'>
  227. <td></td>
  228. <td>$name</td>
  229. <td>$extn</td>
  230. <td>$size</td>
  231. <td sorttable_customkey='$timekey'>$modtime</td>
  232. <td><a target='_blank' href='images1/$namehref'>Watch me</a></td>
  233. </tr>");
  234. }
  235. }
  236. ?>
  237. </tbody>
  238. </table>
  239.  
  240. </div>
  241.  
  242. </body>
  243.  
  244. </html>
RAW Paste Data