Watch out for line wraps. <?php
/* I wrote this for private use, so don't be suprised if it sucks. */ $DIRECTORY = '/path/to/images'; $PATH_ROOT = &$DIRECTORY; // Kind of a document root for this script. if ( isset($_SERVER['PATH_INFO']) && file_exists($DIRECTORY.$_SERVER['PATH_INFO']) && ereg("^$PATH_ROOT", realpath($DIRECTORY.$_SERVER['PATH_INFO'])) ) { $info = pathinfo($DIRECTORY.$_SERVER['PATH_INFO']); switch(strtolower($info['extension'])) { case 'jpe': case 'jpg': case 'jpeg': header("Content-type: image/jpeg"); break; case 'gif': header("Content-type: image/gif"); break; default: exit(); break; } readfile($DIRECTORY.$_SERVER['PATH_INFO']); exit(); } if ($handle = opendir(trim($DIRECTORY))) { $files = array(); while (false !== ($file = readdir($handle))) if ( (strcmp($file, '.') != 0) ) { $info = pathinfo($file); if ( in_array(strtolower($info['extension']), array('jpg', 'jpe', 'jpeg', 'gif')) ) array_push($files, $file); } closedir($handle); $link = $files[mt_rand(0, (sizeof($files)-1))]; echo '<html> <head> <META HTTP-EQUIV=Refresh CONTENT="5; URL='.$_SERVER['REQUEST_URI'].'"/> <title>'.$link.'</title> </head> <body> <center> <a href="'.$_SERVER['REQUEST_URI'].'/'.$link.'">'.$link.'<br/> <img border="0" src="'.$_SERVER['REQUEST_URI'].'/'.$link.'" /></a> </center> </body> </html>'; } ?> On Wednesday 03 September 2003 11:07 pm, John Taylor-Johnston wrote: > I have a directory jammed-packed with images. > I want to read the directory contents /www/usr/htm/images/ > and display randomly any *.gif or *.jpg in said directory. > Do-able? Seriously? Ideas? Places to start? > John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php