Tip, Tricks and Letting off steam

Rotating Images and Files on Webpage

Continue to work on getting my website updated.  It is fun learning new things as I work on the site.    Ive added rotating images to my pages as well as the background using the rotate.php script from Dan P. Benjamin, Automatic, Ltd. The script is very simple to implement copy the file into the directory with your images then call it from your page or from the css file to rotate the background. Dan P. Benjamin, Automatic, Ltd.  random image rotator.  

Sample entry for css file:

background: url(images/random-images/rotate.php);

Sample entry for webpage:

<p align=”center”><img src=”images/photography/rotate.php” alt=”random photos” width=”375″ height=”315″ /></p>

To provide a random id for the images I set a variable using uniqid then generate a random number.  Then add an id to the rotate.php.

Sample Variable for uniq id: /*<?php $ranzyz345 = md5( uniqid (rand(), 1) ); ?>*/

Sample adding uniq id to rotate.php: /*<img src=”images/directory/rotate.php?id=<?php echo($ranzyz345); ?>” title=”” alt=”Random Marine Corps Emblems and Cheverons” width=”125″ height=”125″ style=”float:left; padding-right: 10px; padding-left: 10px;” border=”1.0″/>*/

For  rotating  videos or other  content  randomly I use another php script that read a directory an randomly pulls files from the directory would love to give credit where this file came from but I can”t find it.  But here  is the code, the only change is enter the path to your directory.  I setup a div then use  a include to load the file into the page.

Code for random.php /* error_reporting (E_ALL | E_STRICT); $files = array(); $path = “(path to  directory)/”; if( $handle = opendir( $path ) ) { while (false !== ($file = readdir($handle))) {  if( $file != “.” && $file != “..” && !is_dir( $path.$file ) ) { $files[] = $path.$file; }*/

You need to populate the $files variable before you count it;  /*$file = $files[ rand( 0, count( $files ) -1 ) ];*/

Now we can include it!  /*include (“$file”); } else { print “no files found”}*/

18 Responses to Rotating Images and Files on Webpage

  • Pingback: Jay

Leave a Reply