Page 1 of 1

Directories read to table

Posted: Thu Mar 08, 2007 11:14 am
by Grahamecc
Hi, im trying to write a page that looks in 1 sub directory for a list of games, and then a seperate sub directory for thumnail images for them. I have then tried to get it to produce a table with the thum in one column and the name and hyperlink to load the game in the other, then loop over the array. When i run the page none of the arrays are echo'd, and im not sure how to remove the . and .. from the returned array.

Code: Select all

<?php
if ($handle = opendir('/var/www/html/games/flash/')) {
   while (false !== ($games = readdir($handle))) {
	usort($games, 'strnatcmp');
	}
  closedir($handle);
}

if ($handle = opendir('/var/www/html/games/thum/')) {
   while (false !== ($thums = readdir($handle))) {
	usort($thums, 'strnatcmp');
	$thums=$thum;
}
   closedir($handle);
}
echo "<table summary=\"Games\" width=\"720\" align=\"center\"border=\"0\">\n";
$rows    = ceil( count( $games) );
$counter = 0;
for( $i = 0; $i <$games; $i++ )
{
echo "<tr>";
echo "<td><a href=\"http://grahamserver.hopto.org/games/game.php?id=$games\"><img src=\"./thum/thum$\" width=\"392\" height=\"208\" border=\"0\" alt=\"0\"/></a></td>\n";
echo "<td> '$games'</td></tr>\n";
}
echo "</table>\n";
?>
There are mutiple errors with this but it is only the second page ive made, any help would be appreciated.

Posted: Thu Mar 08, 2007 12:38 pm
by feyd
readdir() does not return an array.

Posted: Thu Mar 08, 2007 1:06 pm
by Grahamecc
hi, thanks for the quick reply, any sugestion of how i should go about getting this working.

Posted: Thu Mar 08, 2007 1:15 pm
by RobertGonzalez
Have you looked at the filesystem pages of the PHP Manual? There are some really good examples in there of doing what you want to do.