Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
List files on directory and build the php/html page
Old 02-14-2011, 02:24 PM List files on directory and build the php/html page
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Hello there!
I'm making a page with some flash games, but, since in the past will be many games it will be very bored to add all those games one by one on the site. I know that using php we can get the list of the files in the directory and i know that, using this method, i can display all the games on the directory to the visitors page but, i was thinking if you can help me to add an image to each game that correspond with the name of the game. Ex:
In "games" folder we will have games: play1.swf, play2.swf, play3.swf
and, in "images" directory we will have images: play1.jpg, play2.jpg, play3.jpg.
To display the list of the games, can we make a combination of jpg files with swf files? Play1.jpg will be the image of play1.swf game and, when a visitor clicks on the image, will be redirect to a page named ex: playgames.php?play1
Can someone help me on this? It will be a big help for my project.
Thank you very much and waiting for your reply!
Kleidi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-14-2011, 02:44 PM Re: List files on directory and build the php/html page
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
If yuo can guarantee there'l always be a corresponding image file, just use basename or pathinfo to get the name component and build the string for the image tag and the link.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 02-15-2011, 05:18 PM Re: List files on directory and build the php/html page
RonnieTheDodger's Avatar
Extreme Talker

Posts: 232
Location: Central USA
Trades: 0
I would probably use a plugin architecture where you have a directory for all your Flash games, and inside are sub-folders for each game.

Each game folder would hold two or three files -- game.swf, icon.jpg, and optionally, a text or php file that will hold basic game information.

Each game you add has this same structure and you just drop the whole folder into it. No numbering required.

Now it is a matter of getting a list of directories (the directory name can be the game name if wanted). It is pretty simple to get the icon and game link without having to pre-number all the files.
__________________
Ronnie T. Dodger

[
Please login or register to view this content. Registration is FREE
] [
Please login or register to view this content. Registration is FREE
]

Last edited by RonnieTheDodger; 02-15-2011 at 05:19 PM..
RonnieTheDodger is offline
Reply With Quote
View Public Profile Visit RonnieTheDodger's homepage!
 
Old 02-16-2011, 09:56 PM Re: List files on directory and build the php/html page
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Create a file and call it whatever you want, put this in the file:

PHP Code:
<?php

if ($handle opendir('images')) {
    while (
false !== ($file readdir($handle))) {
        if (
$file != "." && $file != "..") {
            
$filename explode('.'$file);
            
$filename $filename[0];
            echo 
"<a href='playgame.php?game=$filename'><img src='images/$file' alt='' width='150' /></a>";
            echo 
'<br /><br />';
        }
    }
    
closedir($handle);
}

?>
Next create a file called "playgame.php" and put this in there:

PHP Code:
<?php

$game 
htmlentities($_GET['game']).'.swf';

?>
HTML Code:
<object width="550" height="400">
    <param name="movie" value="games/<?php echo $game; ?>">
    <embed src="games/<?php echo $game; ?>" width="550" height="400"></embed>
</object>
In the directory you put these 2 files you need 2 folders, one called "images" and one called "games". For the script to work the games must all be in .swf format, the images can be in any format. I couldn't attach the working example since file is too large, you can download it here:
Code:
http://rapidshare.com/files/448351168/mygames.zip
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 02-19-2011, 05:46 PM Re: List files on directory and build the php/html page
Experienced Talker

Posts: 32
Name: Kleidi
Trades: 0
Thank you bro ... I'll try and update you.
Thanks again
Kleidi is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to List files on directory and build the php/html page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32812 seconds with 12 queries