Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to: random images
#6
There is a plugin in extend for random content.
http://get-simple.info/extend/plugin/ran...ntent/303/

For random images from a folder I have used this ancient script in the folder I want to get the image from. (if you check the source below it's from 2003 but still there)

With this saved in the folder along with the images as randompic.php
the usage is then
Quote:img src="/wherever the pics are/randompic.php"


The script
PHP Code:
<?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!
?>
Reply


Messages In This Thread
How to: random images - by datiswous - 2014-12-11, 21:26:57
RE: How to: random images - by Lars - 2014-12-12, 19:24:30
RE: How to: random images - by datiswous - 2014-12-12, 22:57:18
RE: How to: random images - by lesh - 2014-12-13, 01:57:44
RE: How to: random images - by datiswous - 2014-12-12, 19:52:57
RE: How to: random images - by Lars - 2014-12-12, 20:29:17
RE: How to: random images - by shawn_a - 2014-12-13, 02:01:07
RE: How to: random images - by datiswous - 2014-12-15, 04:37:44
RE: How to: random images - by Lars - 2014-12-13, 02:44:46
RE: How to: random images - by shawn_a - 2014-12-15, 04:42:28
RE: How to: random images - by datiswous - 2014-12-15, 06:33:23



Users browsing this thread: 1 Guest(s)