Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Sortowanie plików
Agvan
post 6.06.2005, 00:51:14
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 19.05.2005
Skąd: Kraków

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
SongoQ
post 6.06.2005, 01:18:45
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


Upakuj w tablice i wtedy posortuj.


--------------------
Go to the top of the page
+Quote Post
Agvan
post 8.06.2005, 00:55:11
Post #3





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 19.05.2005
Skąd: Kraków

Ostrzeżenie: (0%)
-----


Tak wlasnie myslalem, tyle ze nie umiem sad.gif Moglby mi ktos poprawic ten skrypcik? Bylbym dzwieczny...
Go to the top of the page
+Quote Post
SongoQ
post 8.06.2005, 01:29:37
Post #4





Grupa: Przyjaciele php.pl
Postów: 2 923
Pomógł: 9
Dołączył: 25.10.2004
Skąd: Rzeszów - studia / Warszawa - praca

Ostrzeżenie: (0%)
-----


  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. ?>


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.07.2025 - 17:58