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
 
Start new topic
Odpowiedzi
david8213
post
Post #2





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Dlaczego mi nie działa wyświetlanie ikonek do poszczególnego rozszerzenia ?

  1. //
  2. $display['tif'] = "img/tif.bmp";
  3. $display['bmp'] = "img/bmp.bmp";
  4.  
  5. //
  6.  
  7. global $display, $showsize;
  8.  
  9. //
  10.  
  11. echo '.$display[get_extension($files)].';
  12.  


Jak to zrobić na podstawie powyższych postów

Ten post edytował david8213 24.07.2013, 08:34:49
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: 28.12.2025 - 18:17