Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Sortowanie funkcji dir()
--Jakub--
post
Post #1





Goście







mam skrypt który otwiera katalog i wylistowuje wszystkie pliki. niestety sa one pomieszane:

filename: 10.jpg
filename: 29.jpg
filename: 16.jpg
filename: 28.jpg
filename: 33.jpg
filename: 14.jpg
filename: 37.jpg
filename: 30.jpg
filename: delfin9.jpg
filename: delfin7.jpg
filename: 20.jpg
filename: 17.jpg

potrzebuje aby ten skrypt:

  1. <?php
  2.  
  3. $dir = dir("images/");
  4. while (($file = $dir->read()) !== false)
  5. {
  6. echo "filename: " . $file . "<br />";
  7. }$dir->close();
  8.  
  9. ?>


sortował wyniki alfabetyznie.

pozdrawiam, Jakub
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Spyder
post
Post #2





Grupa: Zarejestrowani
Postów: 269
Pomógł: 7
Dołączył: 12.10.2006
Skąd: Newcastle Upon Tyne

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


Cytat(barthpl @ 11.08.2008, 15:22:17 ) *
A nie lepiej użyć funkcji scandir " title="Zobacz w manualu PHP" target="_manual (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) Zwraca posortowaną zawartość katalogu.
  1. <?php
  2. $filesList = scandir( './images' );
  3. foreach( $filesList as $file )
  4. echo "filename: $file <br />";
  5. ?>


Ten skryp nie sortuje do konca poprawnie oto wynik:

filename: 1.jpg
filename: 10.jpg
filename: 11.jpg
filename: 12.jpg
filename: 2.jpg
filename: 21.jpg
filename: 3.jpg
filename: 6.jpg
filename: 7.jpg
filename: 8.JPG
filename: 9.JPG

Mam podobny skrypt:

  1. <?php
  2. $katalog="upload"; 
  3. $opna=opendir($katalog);
  4. while($element=readdir($opna)){
  5. if($element!="." && $element!=".."){
  6.  $tablica[]=$element;
  7.  }
  8.  }
  9. closedir($opna);
  10. array_multisort ($tablica, SORT_DESC);
  11. foreach ($tablica as $plik){
  12. echo $plik . '<br>';
  13. }
  14.  
  15.  
  16. $filesList = scandir( './upload' );
  17. foreach( $filesList as $file )
  18. echo "filename: $file <br />";
  19.  
  20. }
  21. $i++;
  22. }
  23.  
  24. I tez sortuje tak samo tyle ze z desc i nie mam pojecia jak to obejsc?
  25. ?>


Ten post edytował Spyder 12.08.2008, 00:21:38
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: 6.10.2025 - 19:11