Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z sortowaniem listy :o
Forum PHP.pl > Forum > PHP
graczu
Skrypt:
  1. <html>
  2. <head>
  3.  
  4. <style>
  5. body {
  6. background-color: #ffffff;
  7. font-family: sans-serif;
  8. color: #000;
  9. margin: 0px;
  10. padding: 2em 0px 2em 0px;
  11. }
  12.  
  13. a {
  14. text-decoration: none;
  15. color: #000099;
  16. background-color: #ffffff;
  17. font-weight: normal;
  18. }
  19. a:hover {
  20. background-color: #99CCFF;
  21. background-color: #ffffff;
  22. font-weight: bolder
  23. }
  24. h1 {
  25. text-align: center;
  26. padding-left: 8%;
  27. margin-top: 1em;
  28. background-color: #ddeeff;
  29. font-size: x-large;
  30. border-top: 1px solid #000000;
  31. border-bottom: 1px solid #000000;
  32. clear: both;
  33. }
  34.  
  35. h2 {
  36. padding-left: 8%;
  37. margin-top: 1em;
  38. background-color: #ddeeff;
  39. font-size: large;
  40. border-top: 1px solid #000000;
  41. border-bottom: 1px solid #000000;
  42. clear: both;
  43. }
  44. h3 {
  45. padding-left: 10%;
  46. margin-top: 1em;
  47. background-color: #ddeeff;
  48. font-size: medium;
  49. border-top: 1px solid #000000;
  50. border-bottom: 1px solid #000000;
  51. clear: both;
  52. }
  53.  
  54. h4 {
  55. padding: 0px;
  56. margin: 10px 5% 2px 5%;
  57. font-weight: bold;
  58. color: #000099;
  59. }
  60.  
  61. table {
  62. margin: 2px 5% 2px 5%;
  63. border: none;
  64. }
  65.  
  66. table tr,table td,table th {
  67. border: none;
  68. }
  69.  
  70. ul {
  71. margin: 2px 5% 2px 5%;
  72. }
  73.  
  74. pre {
  75. margin: 2px 5% 2px 5%;
  76.  
  77. }
  78.  
  79. li {
  80. padding-bottom: 0em;
  81. }
  82.  
  83. textarea {
  84. overflow: auto;
  85. }
  86.  
  87. </style>
  88.  
  89. </head>
  90. <body>
  91. <?php
  92.  
  93. /* CFG */
  94. $home_dir = "./";
  95.  
  96. $path = stripslashes($path);
  97.  
  98. /* jeb** hakerow */
  99. if (stristr($path, "../") || stristr($path, "..\\"))
  100.  unset($path);
  101.  
  102. /* By mi patch dir sie nie rozjfalil */
  103. if ($home_dir) $home_dir = realpath($home_dir)."/";
  104. else if (!$home_dir && $os == 2)
  105.  $home_dir = dirname($SCRIPT_FILENAME)."/";
  106.  
  107. /* potem dla katalogow */
  108. if ($path == "/" || $path == "./" || $path == "\\" || $path == ".\\")
  109.  unset($path);
  110.  
  111. /* SCRIPT */
  112.  
  113.  $open = opendir($home_dir.$path);
  114.  for($i=0;($file = readdir($open)) != false;$i++)
  115. if (is_file($home_dir.$path.$file))
  116.  $files[$i] = $file;
  117.  closedir($open);
  118.  
  119.  sort($files,SORT_REGULAR);
  120.  
  121. echo "<h1>Files:</h1>";
  122. echo "
  123. <table width=\"60%\" align=\"left\" valign=\"top\">
  124. <tr>
  125. <td width=\"35%\">File Name:</td>
  126. <td width=\"10%\">-</td>
  127. <td width=\"20%\">File Size:</td>
  128. <td width=\"10%\">-</td>
  129. <td width=\"25%\">Modified:</td>
  130. </tr>
  131. </table>
  132. <br>
  133. <br>
  134. ";
  135. echo "<table width=\"60%\" align=\"left\" valign=\"top\">";
  136.  
  137.  if ($files) foreach($files as $file)
  138.  {
  139.  $modified = date("H:i d-m-Y",filemtime($home_dir.$path.$file));
  140. print "<tr><td width=\"35%\"><li><a href=$path$file>$path$file</a></li></td><td width=\"10%\">-</td><td width=\"20%\">";
  141.  $filesize = filesize($home_dir.$path.$file);
  142.  if ($filesize >= 1048576) print number_format($filesize/1024/1024, 2, ',', '.')."&nbsp;MB";
  143.  else if ($filesize >= 1024) print number_format($filesize/1024, 2, ',', '.')."&nbsp;KB";
  144.  else print number_format($filesize, 0, ',', '.')."&nbsp;B";
  145. print "</td><td width=\"10%\">-</td><td width=\"25%\">";
  146. print "$modified";
  147. print "</td></tr>";
  148. }
  149. echo "</table>";
  150.  
  151.  
  152. ?>


I jak zrobić by sortowało pliki po ich dacie modyfikacji questionmark.gif :x

Skrypt troche chaotyczny ale nic wiecej nie wymyślę, styl wzięty z phpmyadmin, by się nikt nie doczepił ;o
revyag
  1. <?php
  2. foreach($files as $key => $value) {
  3. $mod[$value] = filemtime($home_dir.$path.$value);
  4. }
  5. arsort($mod);
  6. ?>


Tablica mod wygląda tak: nazwa_pliku => data_modyfikacji

Wyświetlasz tak:
  1. <?php
  2. foreach($mod as $key=>$value) {
  3. echo $key," - ",date("H:i d-m-Y",$value),"<br />";
  4. }
  5. ?>
graczu
tzn questionmark.gif

  1. <?php
  2. /*      if ($files) foreach($files as $file) */
  3.     if ($files) foreach($files as $key => $value)
  4.      {
  5.       $mod[$value] = filemtime($home_dir.$path.$value);
  6.          $modified = date("H:i d-m-Y",filemtime($home_dir.$path.$file));
  7.       print "<tr><td width=\"35%\"><li><a href=$path$file>$path$file</a></li></td><td width=\"10%\">-</td><td width=\"20%\">";
  8.          $filesize = filesize($home_dir.$path.$file);
  9.          if ($filesize >= 1048576) print number_format($filesize/1024/1024, 2, ',', '.')."&nbsp;MB";
  10.          else if ($filesize >= 1024) print number_format($filesize/1024, 2, ',', '.')."&nbsp;KB";
  11.          else print number_format($filesize, 0, ',', '.')."&nbsp;B";
  12.       print "</td><td width=\"10%\">-</td><td width=\"25%\">";
  13.       print "$modified";
  14.       print "</td></tr>";
  15.     }
  16. arsort($mod);
  17.  
  18. ?>


not work :X

hehe już działa źle złożyłem smile.gif

  1. <?php
  2. foreach($files as $key => $value) {
  3. $mod[$value] = filemtime($home_dir.$path.$value);
  4. }
  5. arsort($mod);
  6.  
  7. if ($files) foreach($mod as $key=>$value)
  8.  {
  9. print "<tr><td width=\"35%\"><li><a href=$key>$key</a></li></td><td width=\"10%\">-</td><td width=\"20%\">";
  10.  $filesize = filesize($home_dir.$key);
  11.  if ($filesize >= 1048576) print number_format($filesize/1024/1024, 2, ',', '.')."&nbsp;MB";
  12.  else if ($filesize >= 1024) print number_format($filesize/1024, 2, ',', '.')."&nbsp;KB";
  13.  else print number_format($filesize, 0, ',', '.')."&nbsp;B";
  14. print "</td><td width=\"10%\">-</td><td width=\"25%\">";
  15. $modified = date("H:i d-m-Y",filemtime($home_dir.$key));
  16. print "$modified";
  17. print "</td></tr>";
  18. }
  19. echo "</table>";
  20.  
  21. ?>


work
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.