PDA

View Full Version : Php random image selector



splintercell!
03-08-2005, 08:53 PM
Ok does anyone know the code so I can have random images on my page each time the page is refreshed :S I have used one including a flatfile but it just messes up alot so any ideas??? Btw this is for affiliates :)

Dentafrice1
03-08-2005, 09:04 PM
Splinter ill find it give me a sec ok?

Dentafrice1
03-08-2005, 09:06 PM
to Show
<img src="/dropbox/2003/rotate/rotate.php" alt="A Random Image" />



<?php
/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/

// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = '';

// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';

$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>

Dentafrice1
03-08-2005, 09:21 PM
does it work?

[Edited By Partie2] (Forum Moderator) please dont post multiple posts after each other just edit your last one

Mentor
03-08-2005, 09:41 PM
i did a tutoral on dinamicly random images a while ago if thats useful "/

http://habboxforum.com/showthread.php?t=45838

splintercell!
03-08-2005, 09:42 PM
uses the fourm search :) thnx Caleb +rep

iRoss
04-08-2005, 08:32 AM
Mentor wasn't that code for random image in your signature?!


<?php

$stuff = array (
0 => "5.png",
1 => "banner2.png",
2 => "banner3.png",
);
$display=rand(0, sizeof($stuff)-1);

//write banner
echo "<img src='".$stuff[$display]."'>";

?>

splintercell!
04-08-2005, 08:38 AM
no he has sort of placed the file with all that in into his signature..

iRoss
04-08-2005, 08:39 AM
I always wondered how he did that... That tutorial didn't help me really :P

Mentor
04-08-2005, 11:22 AM
its more aless same as the one posted here, exspet it has a load of header info, includes the file and uses htaccess to become a png "/

Want to hide these adverts? Register an account for free!