Trying to create a random flash generator for a page on my website

First off, I’d like to let you all know that my web design experience is at most moderate.

Now, my problem…

I don’t know what it is.

I am trying to load random flash files on this page: http://www.nsgaming.us/random/

the files are located in …/files/flash/

my code for random.php is:

[php]<?php
$imglist=’’;
//$img_folder is the variable that holds the path to the swf files.
// see that you dont forget about the “/” at the end
$img_folder = “…/files/flash/”;
mt_srand((double)microtime()*1000);
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, ad them to a list
while ($file = $imgs->read()) {
if (eregi(“swf”, $file))
$imglist .= "$file “;
} closedir($imgs->handle);
//put all images into an array
$imglist = explode(” ", $imglist);
$no = sizeof($imglist)-2;
//generate a random number between 0 and the number of images
$random = mt_rand(0, $no);
$image = $imglist[$random];
//display random swf
echo ‘’;
?>[/php]

I call it in the index,

<head> <title>test</title> <?php include("../menu.php"); include_once('random2.php'); ?> </head>

(Yes, it is random2.php, I tried two different base codes.)

Any help is appreciated.

You are really over complicating this procedure, try this.
[php]

<?php //$img_folder is the variable that holds the path to the swf files. // see that you dont forget about the "/" at the end $img_folder = "files/flash/"; // You generally don't need the ../ in the path when using the glob() // Gathers a list of files from the specified folder with a swf extension $files = glob($img_folder.'*.swf'); // Grabs a random array key $random = array_rand($files); $image = $files[$random]; //display random swf /*echo ''; */?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service