Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Sortowanie plików
Romskey
post
Post #1





Grupa: Zarejestrowani
Postów: 45
Pomógł: 2
Dołączył: 16.02.2007

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


Mam taki kod :

  1. <?php
  2. $dir="../upload";
  3. function folder_list($dir){
  4. if ($handle = opendir($dir)) {
  5. while (false !== ($file = readdir($handle))) {
  6. echo "<a href=\"../upload/$file\">".$file."</a><br />";
  7. }
  8. closedir($handle);
  9. }
  10. };
  11.  
  12. echo folder_list($dir);
  13. ?>



Czy ktoś mógłby mi pomóc i uzupełnić kod o możliwość
posortowania wyświetlanych wyników ?
Pliki mają nazwy numeryczne i chciałbym aby wyświetlały się
w kolejności (numery nie są kolejne dlatego inkrementacja nie wchodzi w grę )

Dzięki z góry.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
Darti
post
Post #2





Grupa: Zarejestrowani
Postów: 1 076
Pomógł: 62
Dołączył: 6.03.2005
Skąd: Wroc

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


scandir" title="Zobacz w manualu PHP" target="_manual a następnie sort" title="Zobacz w manualu PHP" target="_manual a następnie jakaś pętelka (foreach się nada)

Ten post edytował Darti 21.04.2009, 01:50:02


--------------------
The answer is out there, Neo. It's looking for you. And it will find you, if you want it to.
SERVER_SOFTWARE : Apache/2.2.4 (Win32) PHP/5.2.1
MySQL Client API version : 5.0.27
Go to the top of the page
+Quote Post
Berg
post
Post #3





Grupa: Zarejestrowani
Postów: 180
Pomógł: 37
Dołączył: 1.05.2008
Skąd: Białystok

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


  1. <?php
  2. $dir="../upload";
  3. function folder_list($dir){
  4.    $array_to_sort = array();
  5.    if ($handle = opendir($dir)) {
  6.        while (false !== ($file = readdir($handle))) {
  7.            if(is_file($dir.'/'.$file)) {
  8.            $array_to_sort[] = $file;
  9.            }
  10.        }
  11.    closedir($handle);
  12.    }
  13.    if(!empty($array_to_sort)) {
  14.         sort($array_to_sort);
  15.         $content = '';
  16.         foreach($array_to_sort as $value) {
  17.            $content .= '<a href="'.$dir.'/'.$value.'">'.$value.'</a><br />';
  18.        }
  19.        return $content;
  20.    }
  21.    else return false;
  22. };
  23.  
  24. echo folder_list($dir);
  25. ?>
Go to the top of the page
+Quote Post
Romskey
post
Post #4





Grupa: Zarejestrowani
Postów: 45
Pomógł: 2
Dołączył: 16.02.2007

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


Dzięki wielkie z pomoc.
pozdrawiam smile.gif

Ten post edytował Romskey 21.04.2009, 02:31:50
Go to the top of the page
+Quote Post
piotrooo89
post
Post #5


Newsman


Grupa: Moderatorzy
Postów: 4 005
Pomógł: 548
Dołączył: 7.04.2008
Skąd: Trzebinia/Kraków




hmm Twoje 26 linijek ja zastąpię moimi 8.

  1. <?php
  2. $dir = '../upload/*';
  3. $pok_dir = '../upload';
  4. $pliki = glob($dir);
  5. sort($pliki);
  6. foreach($pliki as $value)
  7. {
  8.    $content .= '<a href="'.$pok_dir.'/'.$value.'">'.$value.'</a><br />';
  9. }
  10. echo $content;
  11. ?>


Ten post edytował piotrooo89 21.04.2009, 14:25:40


--------------------
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 Aktualny czas: 20.08.2025 - 10:40