Boat Drinks  

Go Back   Boat Drinks > General > Computer and Consoles

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 25-02-2010, 22:29   #1
Joe 90
Absinthe
 
Joe 90's Avatar
 
Join Date: Jan 2007
Location: Chester
Posts: 2,345
Default PHP Random Image Script

Code:
<?php
$fileList = array();
$folder = ".";
$handle = opendir($folder);
while (
false !== ( $file = readdir($handle) )
) {
if (
substr($file, -4) == ".gif" ||
substr($file, -4) == ".jpg"
) {
$fileList[count($fileList)] = $file;
}
}
closedir($handle);
$randNum = rand( 0, (sizeOf($fileList) -1) );
if (
substr($fileList[$randNum], -4) == ".gif"
) {
header ("Content-type: image/gif");
} elseif (
substr($fileList[$randNum], -4) == ".jpg"
) {
header ("Content-type: image/jpeg");
}
readfile($fileList[$randNum]);
?>
So, I've got this script running and it displays a random image okay, but it appears that cache can cause the same image to be displayed once, and then again and again for the remainder of the instances where the script is called.
http://www.shuwarriors.net

I'm no programmer so don't know enough about php - is there a way to limit the amount of times 1 image can be posted - or some other kind of fix?
thanks.
__________________
360 Blog | Join GiffGaff | Twitter
Joe 90 is offline   Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 17:56.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.