[nycphp-talk] Listing files... alphabetically
Robert Dumas
rdumas at cmj.com
Tue Nov 25 16:15:26 EST 2003
I'm sort of cutting my teeth in PHP (i know very minor stuff, but I'm
otherwise a newbie) and I'm trying to come up with a directory lister that,
well, lists all the files in subdirectories from $path and does it in
alphabetical order (well, acutally numerical, since the subdirectories are
all numbers). They're all MP3 files and each folder has files named simply
"01.mp3", "02.mp3", etc.
Here's the code I have. I left in a few commented lines, but don't hold that
against me.
<?php
$path = '/usr/local/apache/cmjnetwork.com/htdocs/sirius/';
//$handle = @opendir($path) or die("Unable to open $path");
$handle = opendir($path);
while ( false !== ($file = readdir($handle)) ) {
if($file=='.' || $file=='..' || $file=='index.php')
continue;
if (preg_match("/\.(esp|mp3)$/", $file)){
$filetlist[$file] = filemtime ($path.'/'.$file);
}
}
asort($filetlist); //this is line #35
// reset($filetlist);
while (list ($key, $val) = each($filetlist)) { // this is line 37
echo '<li>'.$key.' => '.$val.'</li>\n';
}
closedir($handle);
?>
The problem I get is that this error message when I try to view it:
Warning: Wrong datatype in asort() call in
/usr/local/apache/cmjnetwork.com/htdocs/sirius/index.php on line 35
Warning: Variable passed to each() is not an array or object in
/usr/local/apache/cmjnetwork.com/htdocs/sirius/index.php on line 37
Does anyone know why?
Cheers.
Robert D.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20031125/7ddce028/attachment.html>
More information about the talk
mailing list