Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rotating flash movies using PHP

Status
Not open for further replies.

jamiebettles

Technical User
Dec 15, 2005
23
DE
Hello everyone,

Complete novice trying to fumble around using PHP for the first time i'm afraid. I've been told that server side scripting provides an easy way to rotate several flash movies I have on the homepage of my website. ie. i want a different flash banner to run along the top of the site every time the homepage is opened.
I guess the basic script for embedding a flash movie is

<object width="550" height="400">
<param name="movie" value="somefilename.swf">
<embed src="somefilename.swf" width="550" height="400">
</embed>
</object>

but if anybody could tell me what i need to add to serve up a random movie from a list of .swf files, I would be extremely grateful,

thanks very much

jamie
 
There are several ways to do this. One is a combination of filename with a randomizer - file##.swf
In that case you would only need to set the numbers to be picked for the range ## covers.

Alternatively you can put the filenames into an array and use the randmozation function to get the offset (index) and print out the name of that element.

Last method, bery easy, is array plus shuffle:

Code:
<?php
$swf[] = "somefileA.swf";
$swf[] = "somefileB.swf";
$swf[] = "somefileC.swf";
# next line only if PHP Version < 4.2.0
srand((float)microtime() * 1000000);

shuffle($swf);
?>
<object width="550" height="400">
<param name="movie" value="somefilename.swf">
<embed src="<? echo $swf[0];?>" width="550" height="400">
</embed>
</object>
 
Thank you very much. As you can tell I'm in the early stages of learning PHP so your help is invaluable, I've not seen the shuffle function before so thank you for showing me.

jamie
 
Hi.
So here is the script ive come up with after adapting it to the golive layout thats used for the page and the 4 movies i'm rotating, which ive now called 1.swf, 2.swf, 3.swf and 4.swf

<tr>
<td colspan="3" width="860"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=" height="100" width="740">
<?php $num = rand(1, 4); ?>
<object width="740" height="100">
<param name="scale" value="noborder">
<param name="movie" value="<?php echo $num; ?>.swf">
<param name="quality" value="best">
<param name="play" value="true">
<embed pluginspage=" src="<?php echo $num; ?>.swf" width="740" height="100" quality="best" play="true" scale="noborder">
</embed>
</object></td>
</tr>

however...it still doesnt work. could anyone please tell me where ive gone wrong?

Thank you so much for bearing with my idiocy and complete lack of PHP knowlege.

jamie
 
Maybe you could tell us what actually happens. "Doesn't work" is not enough information to respond.
Please elaborate.
 
Hey, ok sorry. Right here's a fuller explanation...

I've tested the PHP code by putting it on its own in a .php file, uploading it to the site and looking at what comes out, and it produces the desired result... ie.

<?php $num = rand(1, 4); ?>
"<?php echo $num; ?>.swf">

this produces "1.swf", "2.swf" etc. each time the page is refreshed.

Then I tested the .swf files to check their locations...for example one of them is and they all are present and correct.

I've tweeked out a few syntax errors i found so my code now looks like this...

<td colspan="3" width="860"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=" height="100" width="740">
<?php $num = rand(1, 4); ?>
<param name="scale" value="noborder">
<param name="movie" value="<?php echo $num; ?>.swf">
<param name="quality" value="best">
<param name="play" value="true">
<embed height="100" pluginspage=" src="<?php echo $num; ?>.swf" width="740" quality="best" play="true" scale="noborder">

</object></td>

But GoLive can't seem to understand the PHP script because when online the space where one of the movies should be running comes up blank and when you go to Safari>Window>Activity the site comes up with an error and where the /2.swf should be, it just says a whole load of garbled text like P20%sw%H etc.

I hope that helps and i hope you can help me out!
thanks again,

jamie
 
Ok problem solved. DRJ478 thanks very much for the suggestions. In the end it was the fact that my file containing the script was a .html file and not a .php file which was screwing everything up.
Thanks again, have a good day,

jamie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top