note 19149 added to function.readdir
| From: | oneredding at yahoo dot nospam dot com | Date: | Mon, 18 Feb 2002 08:52:47 +0000 |
| Subject: | note 19149 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-26729@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\"> {$files[$i][size]} kb</font></td>\n\t</tr>\n";
}
echo "</table>\n</body>\n</html>";
?>
--
http://www.php.net/manual/en/function.readdir.php
http://master.php.net/manage/user-notes.php?action=edit+19149
http://master.php.net/manage/user-notes.php?action=delete+19149
http://master.php.net/manage/user-notes.php?action=reject+19149