Greetings,
Here is a little PHP script I wrote to easily pull any images and randomize them from a directory in your rootpath / webserver.
Instructions:
1. Create a new PHP file called randomimage.php
2. In this file, add the following code:
Code:
<?php
/* Name: Random Image Script
* Version: 1.0.0
* Created by: CyberGeek
* Email: cybergeek@xtremepc-solutions.com
* Website: http://blog.xtremepc-solutions.com
* For Suppor please contact me at my email address.
*/
/* INSTRUCTIONS
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to
* Appear: <?php include "randomimage.php"; ?>
*/
// Change this to the total number of images in the folder
$total = "15";
// Change to the type of files to use eg. .jpg or .gif or .png
$file_type = ".jpg";
// Change to the location of the folder containing the images
$image_folder = "images/random";
// Do NOT edit the the following lines of code below.
$start = "1";
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";
?>
3. Save and upload this file to your host.
4. Now, for any PHP page that you want to insert / show the random images, insert this line of code there:
Code:
<?php include "randomimage.php"; ?>
5. Save that file, and view it a couple of times and make sure it works flawlessly.
Remeber you can change and edit some of the variables in the script. Actually you will most likely need to edit
$total = "15"; that one to have the same number of images as you do in your
images/random directory.
Have FUN!
_________________
Best Regards:
Aaron McGowan (aka: CyberGeek, =cipher=)
CyberGeek's Software Solutions
-- WWW: http://www.cybergeeksoftware.com
-- Tech Line: 1-519-860-4557
-- Email: cybergeek@cybergeeksoftware.com