Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Sortowanie plików
Forum PHP.pl > Forum > Przedszkole
Agvan
Witam!
Mam taki oto skrypt:
  1. <?
  2. function getfilesize($bytes) {
  3.  if ($bytes >= 1099511627776) {
  4.  $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
  5.  $suffix = &#092;"TB\";
  6.  } elseif ($bytes >= 1073741824) {
  7.  $return = round($bytes / 1024 / 1024 / 1024, 2);
  8.  $suffix = &#092;"GB\";
  9.  } elseif ($bytes >= 1048576) {
  10.  $return = round($bytes / 1024 / 1024, 2);
  11.  $suffix = &#092;"MB\";
  12.  } elseif ($bytes >= 1024) {
  13.  $return = round($bytes / 1024, 2);
  14.  $suffix = &#092;"KB\";
  15.  } else {
  16.  $return = $bytes;
  17.  $suffix = &#092;"Byte\";
  18.  }
  19.  if ($return == 1) {
  20.  $return .= &#092;" \" . $suffix;
  21.  } else {
  22.  $return .= &#092;" \" . $suffix . \"\";
  23.  }
  24.  return $return;
  25. }
  26.  
  27.  
  28. if ($_GET[&#092;"path\"]==\"\") {
  29. $path = &#092;"./download\";
  30. } else {
  31. $path=$_GET[&#092;"path\"];
  32. }
  33.  
  34. echo &#092;"<center><table width=100%><tr><td></td></tr>\";
  35.  
  36. if ($handle = opendir($path)) {
  37. while (false !== ($file = readdir($handle))) {
  38. if ($file != &#092;".\" && $file != \"..\") {
  39. if (is_dir(&#092;"$path/$file\")==true){
  40.  
  41. $czas = date(&#092;"d-m-Y\",filectime(\"$path/$file\"));
  42.  
  43.  
  44.  echo &#092;"<tr><td><img src=./images/folder.gif /></td><td><a href=download.php?path=$path/$file>$file</a></td><td align=right></td><td align=right> $czas</td> </tr>\";
  45.  
  46. }else{
  47.  $wielkosc = getfilesize(filesize(&#092;"$path/$file\"));
  48. $czas = date(&#092;"d-m-Y\",filectime(\"$path/$file\"));
  49.  echo &#092;"<tr><td><img src=./images/file.gif /></td><td><a href=$path/$file>$file</a></td><td align=right>$wielkosc</td><td align=right> $czas</td> </tr>\";
  50. }
  51.  
  52. }
  53. }
  54. closedir($handle);
  55. }
  56. echo &#092;"</table></center>\";
  57.  
  58. ?>

...i pytanie co zrobic zeby sortowal pliki alfabetycznie?
SongoQ
Upakuj w tablice i wtedy posortuj.
Agvan
Tak wlasnie myslalem, tyle ze nie umiem sad.gif Moglby mi ktos poprawic ten skrypcik? Bylbym dzwieczny...
SongoQ
  1. <?
  2. function getfilesize($bytes) {
  3.  if ($bytes >= 1099511627776) {
  4.  $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
  5.  $suffix = &#092;"TB\";
  6.  } elseif ($bytes >= 1073741824) {
  7.  $return = round($bytes / 1024 / 1024 / 1024, 2);
  8.  $suffix = &#092;"GB\";
  9.  } elseif ($bytes >= 1048576) {
  10.  $return = round($bytes / 1024 / 1024, 2);
  11.  $suffix = &#092;"MB\";
  12.  } elseif ($bytes >= 1024) {
  13.  $return = round($bytes / 1024, 2);
  14.  $suffix = &#092;"KB\";
  15.  } else {
  16.  $return = $bytes;
  17.  $suffix = &#092;"Byte\";
  18.  }
  19.  if ($return == 1) {
  20.  $return .= &#092;" \" . $suffix;
  21.  } else {
  22.  $return .= &#092;" \" . $suffix . \"\";
  23.  }
  24.  return $return;
  25. }
  26.  
  27.  
  28. if ($_GET[&#092;"path\"]==\"\") {
  29. $path = &#092;".\";
  30. } else {
  31. $path=$_GET[&#092;"path\"];
  32. }
  33.  
  34. echo &#092;"<center><table width=100%><tr><td></td></tr>\";
  35.  
  36. if ($handle = opendir($path)) {
  37. while (false !== ($file = readdir($handle))) {
  38. if ($file != &#092;".\" && $file != \"..\") {
  39. if (is_dir(&#092;"$path/$file\")==true)
  40. {
  41. $aPliki[$file]['typ'] = 'dir';
  42. $aPliki[$file]['czas'] = date(&#092;"d-m-Y\",filectime(\"$path/$file\"));
  43. $aPliki[$file]['path'] = $path;
  44. }
  45. else
  46. {
  47. $aPliki[$file]['typ'] = 'file';
  48. $aPliki[$file]['czas'] = date(&#092;"d-m-Y\",filectime(\"$path/$file\"));
  49. $aPliki[$file]['path'] = $path;
  50. $aPliki[$file]['wielkosc'] = getfilesize(filesize(&#092;"$path/$file\"));
  51. }
  52. }
  53. }
  54. closedir($handle);
  55.  
  56. ksort($aPliki);
  57.  
  58. print_r($aPliki);
  59.  
  60. foreach($aPliki as $szPlik => $aWpis)
  61. {
  62. if($aWpis['typ'] == 'dir')
  63. echo '<tr><td><img src=./images/folder.gif /></td><td><a href=download.php?path='.$aWpis['path'].'/'.$szPlik.'>'.$szPlik.'</a></td><td align=right></td><td align=right>'.$aWpis['czas'].'</td> </tr>';
  64. else
  65. echo '<tr><td><img src=./images/file.gif /></td><td><a href='.$aWpis['path'].'/'.$szPlik.'>'.$szPlik.'</a></td><td align=right>'.$aWpis['wielkosc'].'</td><td align=right>'.$aWpis['czas'].'</td> </tr>';
  66.  
  67. }
  68.  
  69.  
  70. }
  71. echo &#092;"</table></center>\";
  72.  
  73. ?>
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.