I'm new to PHP and this seems like I'm just asking for code but in reality I want to know how to implement a link along with the random selector.
My code:
<?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 (preg_match("/\.swf$/i", $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 '<embed src="'.$img_folder.$image.'" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" width="650"
height="450"></embed>';
?>
This basically grabs a random flash file from my site's directory. Since it won't affect the URL bar, they won't be able to send something they like to someone (which is an unintentional security feature). I want them to be able to send a link or possibly direct click to download.
Also, I was thinking of as well as the random generator, to make a left and right arrow that they can scroll through all the .swf's in the chosen directory, if possible.
the site is www.nsgaming.us and it's the 'Random' button under the text logo.