random image with linkage

  • floridafishandhunt.com
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Florida

Post 3+ Months Ago

Hey everyone check out the header image on my page "shark image"
http://www.floridafishandhunt.com
That image links my guests to my forum.
I need to know the best way (code) to make that image a random image. I would like to have a folder on my server named random images and just drop them into it and it would display them for me.
I also dont want to have to recode every time I do a new image.
If I have to then I guess its ok its not that big of a deal.

I have foud this script
http://www.scriptarchive.com/ssi_image.html

Problem is I am not familiar with ssi
Server SIde Includes.

Anyone have a better suggestion
maybe some simple html or something?

Thanks in advance.
-Doug
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Well, you're gonna need to look at some server side scripting... PHP would be the best way...

Have it do a listing of the entire directory. Store them all in an array, then pick a random one from that array to include in the page. I'm not sure of the exact code off-hand, and I've got to run out in a minute, but if you've not sorted anything out by the time I get back, I'll see what info I can hunt out for you.
  • floridafishandhunt.com
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Florida

Post 3+ Months Ago

What do you think of this axe?



<html>
<head>
<title></title>
</head>
<body>
<script language="javascript">
<!--
var b1dis = "<a href=\"";
var bdis = "\"><img src=\"";
var edis = " width=\"110\" height=\"100\" alt=\"some text\" border=\"0\"></a>";
var rnumb = "";
var img = "";

rnumb += Math.floor(Math.random()*3);
img = rnumb;

if (img == "0") {
document.write(b1dis+ "page1.html" +bdis+ "images/page1.gif\"" +edis);
}

if (img == "1") {
document.write(b1dis+ "page2.html" +bdis+ "images/page2.gif\"" +edis);
}

if (img == "2") {
document.write(b1dis+ "page3.html" +bdis+ "images/page3.gif\"" +edis);
}

// -->
</script>
</body>
</html>
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

You could do it with JavaScript if you knew exactly what images are there beforehand, but you'd have to edit it every time you uploaded a new image...

With PHP, you can have it detect all the images server-side. It would also mean the code doesn't go down to the end-user. So, they don't see all the others, and they don't have to download an extra coupla K's worth of JavaScript with each page (It's not a lot, but it can slow down dialup users to the point of annoyance) :)
  • floridafishandhunt.com
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Florida

Post 3+ Months Ago

I have found some more php stuff , but everything I have found looks like it doesnt allow the user to click the image .?


http://www.tecnorama.org/document.php?id_doc=57

check that out.
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Well this would work:
Code: [ Select ]
<?
// save as image.php
$folder=opendir("./path/to/images");
while ($file = readdir($folder))
$names[count($names)] = $file;
closedir($folder);
sort($names);
$tempvar=0;
for ($i=0;$names[$i];$i++){
$ext=strtolower(substr($names[$i],-4));
if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
}
srand ((double) microtime() * 10000000);
$rand_keys = array_rand ($names1, 2);
$image=$names1[$rand_keys[0]];
// change the height and width to your image demensions
else {echo "<img src=\"http://www.urltoimagefolder.com/$image\" width=\"225\" height=\"112\">";}
?>
  1. <?
  2. // save as image.php
  3. $folder=opendir("./path/to/images");
  4. while ($file = readdir($folder))
  5. $names[count($names)] = $file;
  6. closedir($folder);
  7. sort($names);
  8. $tempvar=0;
  9. for ($i=0;$names[$i];$i++){
  10. $ext=strtolower(substr($names[$i],-4));
  11. if ($ext==".jpg"||$ext==".gif"||$ext=="jpeg"||$ext==".png"){$names1[$tempvar]=$names[$i];$tempvar++;}
  12. }
  13. srand ((double) microtime() * 10000000);
  14. $rand_keys = array_rand ($names1, 2);
  15. $image=$names1[$rand_keys[0]];
  16. // change the height and width to your image demensions
  17. else {echo "<img src=\"http://www.urltoimagefolder.com/$image\" width=\"225\" height=\"112\">";}
  18. ?>

Then where you want the images to be displayed put:
Code: [ Select ]
<? include "image.php";?>
  • floridafishandhunt.com
  • Graduate
  • Graduate
  • User avatar
  • Posts: 130
  • Loc: Florida

Post 3+ Months Ago

thanks everyone!
Php with that php script can you make those random images have links assigned to them?
-Doug
  • phpSelectah
  • Student
  • Student
  • User avatar
  • Posts: 97

Post 3+ Months Ago

sure, you can do something like:

Code: [ Select ]
<?
//random target method
//phpSelectah
//3/21/04

// create an array of possible targets
  $targets[] = "http://www.google.com";
  $targets[] = "http://www.ozzu.com";
  $targets[] = "http://slashdot.org";
  $targets[] = "http://us3.php.net";


  $target = $targets[mt_rand(0,count($targets) - 1)];  //get random image from array using marsienne twister

   //output link to browser
   print "<a href=\"$target\"><img src=\"http://yourserver.com/pic.php\" border=\"0\"></a>";
?>
  1. <?
  2. //random target method
  3. //phpSelectah
  4. //3/21/04
  5. // create an array of possible targets
  6.   $targets[] = "http://www.google.com";
  7.   $targets[] = "http://www.ozzu.com";
  8.   $targets[] = "http://slashdot.org";
  9.   $targets[] = "http://us3.php.net";
  10.   $target = $targets[mt_rand(0,count($targets) - 1)];  //get random image from array using marsienne twister
  11.    //output link to browser
  12.    print "<a href=\"$target\"><img src=\"http://yourserver.com/pic.php\" border=\"0\"></a>";
  13. ?>


And place this in your index page.

:D

hTh

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 101 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.