Seite 1 von 1

[php] readdir sortieren...

Verfasst: 13.02.2007 23:01
von Asmodiel
Hi!
ich hab hier ne tolle funktion, nur leider kommen die dateien unsortiert raus und ich möchte sie von a-z sortiert haben:

Code: Alles auswählen

function image_list($dir)
{
    echo "<table border='1' width='800' class='main' cellpadding=3 cellspacing=0>";
    echo "<tr><td class='catLeft'><b>List of Files in $dir</b></td>";
    echo "<td class='catLeft'><p align='center'><b>Befehle</b></p></td>";
    echo "<td class=catLeft align=center><b>Dateigröße</b></td>";
    echo "<td class=catLeft align=right><b>Bearbeitet am:</b></td></tr>";
    echo "<tr><td><a href=uploads/games/>Games/</a></td><td align=center>&nbsp;</td><td align=center>Ordner</td><td>&nbsp;</td></tr>";
        if (is_dir($dir)) 
        {
            if ($dh = opendir($dir)) 
            {
                while (($file = readdir($dh)) !== false )
                {
    

		   $path = $dir.$file;
                    if ( $file != 'Thumbs.db' && $file != 'index.html' && $file != 'upload.ico' && $file != 'cellpic1.gif' && is_file($path) )
                    {
                        //Befehllinks
                        echo "<tr>";
                        //Dateiname
                        echo "<td><a href=".$dir.$file.">". $file . " </a></td>\n";
                                                echo "<td align='center'><a href='download.php?file=$file'>Download</a>";
                        echo " :: ";
                        echo "<a href='rename.php?get=$file'>Umbenennen</a>";
                        echo " :: ";
                        echo "<a href=confirm.php?get=$file>Löschen</a></td>";
                        //Dateigröße
                        file_size($path);
                        //Geändert am
                        $ctimestamp = filectime($dir.$file);
	                    $ctime = date('m.d.Y h:i:s a', $ctimestamp);
	                    echo "<td align=right>$ctime</td>";
                        echo "</tr>";

                    }
                }
        closedir($dh);
            }
        }
echo "</table>";
}
es geht halt vor allem um das readdir... :D

ich hoffe, ihr könnt mir helfen und verweist nicht auf iwelche tuts, da ich die meisten, die ich kenne schon durchgeschaut hab und nichts gefunden...

danke im vorraus,
gruß!
asmodiel

Verfasst: 13.02.2007 23:11
von Garnele
Hallo

Hab jetzt nur einen Blick auf die Funktion readdir geworfen, aber ich glaube sie gibt die Ergebnisse in Form eines Arrays zurück, oder? Folglich sollte sich dieser mit asort() sortieren lassen.

Lg
garnele

Verfasst: 14.02.2007 20:57
von Asmodiel
also ich hab mir das jetzt vom php.net tut rasugeholt :

Code: Alles auswählen

$dir = "uploads/";
   $opendir = opendir($dir);
       while (false !== ($filename = readdir($opendir))) {
           $files[] = $filename;
       }
   sort($files);
       foreach ($files as $file) {
           if ( $file != '.' && $file != '..' && $file != '.htaccess' && $file != 'Thumbs.db' && $file != 'index.html' && $file != 'upload.ico' && $file != 'cellpic1.gif' && $file != 'games')
           {
                        //Befehllinks
                        echo "<tr>";
                        //Dateiname
                        echo "<td><a href=".$dir.$file.">". $file . " </a></td>";
                        echo "<td align='center'><a href='download.php?file=$file'>Download</a>";
                        echo " :: ";
                        echo "<a href='rename.php?get=$file'>Umbenennen</a>";
                        echo " :: ";
                        echo "<a href=confirm.php?get=$file>Löschen</a></td>";
                        //Dateigröße
                        $path = $dir.$file;
                        file_size($path);
                        //Geändert am
                        $ctimestamp = filectime($dir.$file);
	                    $ctime = date('m.d.Y G:i:s', $ctimestamp);
	                    echo "<td align=right>$ctime</td>";
                        echo "</tr>";
           }


} echo "</table>"; }
die table fängt schon vorher an!