Is it possible to load random jpeg files every time a page is visited. ie- every time the page is viewed, a random image is displayed instead of the usual image.
Cheers
Karl
Is it possible to load random jpeg files every time a page is visited. ie- every time the page is viewed, a random image is displayed instead of the usual image.
Cheers
Karl
Greg K posted this at 19:46 — 29th January 2005.
He has: 1,667 posts
Joined: Nov 2003
You can use a script to do this, either Client Side (via javascript) or Server Side. See http://209.68.38.102/limo/randpic.php for a script I wrote that lets me have changing icons in another forum I frequest.
The code for the PHP one is:
<?$randval = rand(1,4); // generate a number from 1 to 4
$fname = "limo-0" . $randval . ".jpg";
$fp = fopen ($fname, "r");
while (!feof ($fp)) echo fgetc($fp);
fclose($fp);
?>
'
I have this code in a directory (limo) and also have 4 images in there, limo-01.jpg, limo-02.jpg, limo-03.jpg and limo-04.jpg.
-Greg
[This space intentionally left blank]
Cool Geek Supplies: www.ThinkGeek.com
ValleyPages posted this at 12:43 — 6th February 2005.
He has: 46 posts
Joined: Nov 2001
Greg, something wrong with that file.
andy206uk posted this at 23:50 — 30th January 2005.
He has: 1,754 posts
Joined: Jul 2002
or if you don't have php... here's a javascript version:
<script language="JavaScript"><!--
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>
'
Simply place it in your HTML anywhere between the body tags and update the image links in the array where prompted.
Andyk
Blog of a Web Designer
Give a man a fish and you feed him for a day. Teach him to use the Net and he won't bother you for weeks.
CptAwesome posted this at 05:01 — 7th February 2005.
He has: 370 posts
Joined: Dec 2004
You mean the following jibberish?
= ハル「.,\,T靫ネ%0ED?Jォフ-;"シ{i誄嫩-SA/モクW・Vヲモィ・姓簽蟹 綣#UムNオホーソ]5薈
What that script is doing is opening the actual image file, and writing all the data into the browser, and the browser should read it, BUT you should add
<?header("Content-Type: image/jpg");
$randval = rand(1,4); // generate a number from 1 to 4
$fname = "limo-0" . $randval . ".jpg";
$fp = fopen ($fname, "r");
while (!feof ($fp)) echo fgetc($fp);
fclose($fp);
?>
'
<? echo implode('',explode('|','A|W|E|S|O|M|E')); ?>
http://www.free-online-web-tools.com