note 19149 rejected from function.readdir by sander

From: Date: Sat, 06 Apr 2002 19:16:48 +0000
Subject: note 19149 rejected from function.readdir by sander
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-28759@lists.php.net to get a copy of this message
Sort and list all the sound files (if they are mp3 or wav files) in the current directory dynamically, using a multidimensional array and readdir (don't forget the curly brackets!): <? $handle=opendir('.'); while ($file = readdir($handle)) { if (substr($file, -3) == "wav" | substr($file, -3) == "mp3") { $files[] = array(name => $file, size => intval(filesize($file)/1024)); } } closedir($handle); sort($files); //begin the html and table code echo "<html>\n<head>\n<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1252\">\n<title>Sound Files</title>\n<body bgcolor=\"#ffffff\">\n<b><font face=\"arial, helvetica, geneva\">Sound Files:</font></b><br><br>\n"; echo "<table bordercolor=\"#000000\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n\t<tr>\n\t\t<td align=\"center\"><font size=\"2\" face=\"arial, helvetica, geneva\"><b>Name</b></font></td>\n\t\t<td align=\"center\"><font size=\"2\" face=\"arial, helvetica, geneva\"><b>Size</b></font></td>\n\t</tr>\n"; //loop through the table rows for ($i = 0; $i <= count($files)-1; $i++) { echo "\t<tr>\n\t\t<td align=\"left\"><a href=\"{$files[$i][name]}\"><font size=\"2\" face=\"arial, helvetica, geneva\">{$files[$i][name]}</a></font></td>\n\t\t<td align=\"right\"><font size=\"2\" face=\"arial, helvetica, geneva\">&nbsp;{$files[$i][size]} kb</font></td>\n\t</tr>\n"; } echo "</table>\n</body>\n</html>"; ?>

« previous php.notes (#28759) next »