Directories read to table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Grahamecc
Forum Newbie
Posts: 2
Joined: Sat Mar 03, 2007 1:22 pm
Location: UK

Directories read to table

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

readdir() does not return an array.
Grahamecc
Forum Newbie
Posts: 2
Joined: Sat Mar 03, 2007 1:22 pm
Location: UK

Post by Grahamecc »

hi, thanks for the quick reply, any sugestion of how i should go about getting this working.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply