by Hiroshi on June 18th, 2008
Put all your swf files in a folder named as ‘images’ or whatever you name it (change folder name in script) and use this script to display a random flash movie, everytime page loads.
PHP 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 = "images/"; 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 '<embed src="'.$img_folder.$image.'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="100" height="100"></embed>'; ?>
Random SWF On Page Load Script Download
If you want to display random image on page load called from a specific folder then change file extension from swf to jpg or gif or png in above code and replace embed code with image code as following. Adjust image size according to your need.
Random Image Display Onload PHP Script
<?php $imglist=''; //$img_folder is the variable that holds the path to the swf files or images files. // see that you dont forget about the "/" at the end $img_folder = "images/"; 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("jpg", $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 '<img src="'.$img_folder.$image.'" width="100" height="100">'; ?>
flash, Flash & PHP, random, random content, Randomizing
16 Reviews
Leave a Review
Incoming Searches
php onload, how do you get a page to display a random swf file, random flash php, flash swf script, php code play movies, php script upload swf, php show swf same page, php swf, php swf edit, php swf embed, php swf play, play swf onload, php tag cloud script explode, play 2 swf files in php, play random flash movies on a page, play random swf from a folder in flash, Php script image dynamic when onload, php script embed swf, php onload example, php onload post, php open sfw, php play swf file, php random code loop, php random file if swf, php random flash, php random flash images, php random image and flash, php random include swf, php random jpg, php random swf, php read directory script, php rotate swf directory, put a swf in php, random data swf free, random embed script swf, script to list array of movies in a directory, scripting php dan swf, scripting to make a book in flash, showing a random swf



this is the best solution of any that I have seen.
Thank you!!
Thanks … this has been a life saver for me. I do have a question though. Once a random swf is playing, can it be set to play the other files in the directory in an endless loop until the page is reloaded?
@Kevin: Of course. Just try that. Echo that whatever you want in loop. Any file.
I should have mentioned that I’m just learning … how do I do that? Thanks again!
@Kevin: Okay you have to just change swf in following line
if (eregi(“swf”, $file))
which becomes
if (eregi(“jpg”, $file))
in case of jpg images
and change the lines in echo for images.
echo > img src tags instead of embed tags
See the second example I posted above.
Great … thanks again!
me the script works correctly, but what if I want to put a swf with transparent background? Where do we draw the parameters?
hi nice script..used it..and working fine. i have a question, though. how can we make it go to next swf or previous swf files?
Hi
Thanks for this wonderful information it help me alot..
@sid: Just refresh the page. Its random! Remember?
@Francisco Aldunate: There is a wmode parameter for flash files to make these transparent.
See here: http://www.techmynd.com/how-to.....ansparent/
I have been searching forever for a script like this. Thanks!!! I do have one question though. I am only working with 3 swf files right now and it pulls up the same one over and over quite often. Is there a way to change this code to make it pull them in order instead of randomly? I am very, very new to PHP so please be specific. Thanks for you help.
WOW!… amazing… this has been a tough one to find out there.
Is there a way that I can supress the #55555 random number at the end of the url?
Awesome code thanks! Is there a way to have it pull random files from a folder that contains gifs and swf files. For instance, on one load it might be a swf but on another load it may be an animated gif.
Is it possible to allow full screen in the PHP code?
@flashcode: Nop!That would be using javascript. See this: http://www.webstylepress.com/j.....-part-1/3/