Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]DirectoryIterator sortowanie wyniku
!*!
post
Post #1





Grupa: Zarejestrowani
Postów: 4 298
Pomógł: 447
Dołączył: 16.11.2006

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


Tym sposobem odczytuję listę plików w katalogu, pomijając . oraz .. :
  1. $directory = 'folder';
  2.  
  3. foreach (new DirectoryIterator($directory) as $files) {
  4.  
  5. $onlydirectory = !$files -> isDot() and !$files -> isDir() and !$files -> isExecutable();
  6. $filename = $files -> getFilename();
  7. $date = $files -> getMTime();
  8. $date = date("d-m-Y H:i", $date);
  9.  
  10. $size = $files -> getSize();
  11. $sizeinkb = round($size/1024);
  12.  
  13. if($onlydirectory) {
  14.  
  15.  
  16. echo '<tr class="'. $class.'"><td class="tdf"><input type="checkbox" /></td><td class="tdf">'.imagefile($filename).'</td><td class="tdk">'.$filename.'</td><td class="tdn">'.$size.'</td><td class="tdn">'.$date.'</td><td class="tdu">edycja</td><td class="tdu">usun</td></tr>';
  17.  
  18.  
  19. }
  20.  
  21. }


Chciałbym nazwy plików posortować alfabetycznie:

  1. $directory = 'folder';
  2.  
  3. foreach (new DirectoryIterator($directory) as $files) {
  4.  
  5. $onlydirectory = !$files -> isDot() and !$files -> isDir() and !$files -> isExecutable();
  6. $filename = $files -> getFilename();
  7. $date = $files -> getMTime();
  8. $date = date("d-m-Y H:i", $date);
  9.  
  10. $size = $files -> getSize();
  11. $sizeinkb = round($size/1024);
  12.  
  13. if($onlydirectory) {
  14.  
  15.  
  16. $filetab[] = $filename;
  17.  
  18.  
  19. }
  20.  
  21. }
  22. sort($filetab);
  23.  
  24.  
  25. foreach ($filetab as $filename) {
  26. echo '<tr class="'. $class.'"><td class="tdf"><input type="checkbox" /></td><td class="tdf">'.imagefile($filename).'</td><td class="tdk">'.$filename.'</td><td class="tdn">'.$sizeinkb.'</td><td class="tdn">'.$date.'</td><td class="tdu">edycja</td><td class="tdu">usun</td></tr>';
  27.  
  28. }


Jednak nie wiem czy robię to dobrze, oraz jak odczytać w foreach inne dane?

Kod
foreach ($filetab as $filename && )
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 26.12.2025 - 21:46