added png
the snippet is
$folder = ’images’;
$i = 0;
$imgDir = opendir ($folder);
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif|png",$file_type );
if ( $file != ’.’ && $file != ’..’ && $is_image )
{ $images[$i++] = $file; }
}
closedir ($imgDir);
srand( (double) microtime()*1000000 );
$image_name = $folder . ’/’ . $images[rand( 0,sizeof( $images ) -1 )];
//ends script if no images found
if ( $i == 0 )
die();
return "background=’$image_name’" ;
usage
put the call to the snippet in the table, div or background into the <>
example
<td width="30%" height="100%" valign="top" [[RandomImage]] bgcolor="#F4F4F4">content</td>
put [! !] if you want to update on browser reload (dont tested i dont want it)
change the folder to the direction of your image folder
[based on etomite random image snippet]
-
☆ A M B ☆
- 24,524 Posts
Quote from: xyzvisual at Oct 02, 2005, 05:08 AM
$is_image = eregi( "jpg|gif",$file_type );
Might want to add png to that.
Great snippet !
Thanks for sharing.
Best regards,
zi
Is it posible to add a chek to see if the image is not a thumb? fck editor generates thubs in the same folder.
somthines i like to set the image my self using fckeditor but then the random image snippet also display’s those .thumb_ files.
my PHP knowledge is not so good that i can do that, but i think it ist not to hard to do somthing like if .thumb_* then do not put in array but how to translate my sessemistreet language into php.
hope that somone can help me.
Greets Dimmy
-
☆ A M B ☆
- 24,524 Posts
You can kill three birds with one regexp if you just exclude all files that begin with a .
Thanks a lot this works great
Hi all!
How can I set the image size? thanks!