View Full Version : Random Picture PHP


Vicious101
03-30-2004, 10:36 PM
this is one of those copy and paste tuts

first were gonna make a new folder now put all the pics into the folder and now open up word put this in

<?
$folder=opendir(".");
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"||$ext==".swf"){$names1[$tempvar]=$names[$i];$tempvar++;}
}

srand ((double) microtime() * 9999999999999999);
$rand_keys = array_rand ($names1, 2);
$slika=$names1[$rand_keys[0]];

if (!isset($tnsize)) {

header ("Location: $slika");

}
?>

now save it as a .php and also put it into your new folder

now to disply the random pics

put in <img src=link to random.php>

thats what i did and it works for me

pleaz enjoy

pepsidemon
03-31-2004, 01:30 AM
If they're confused,this one works(even with pages,only if you know includes,of course).

<?php

$randomvar=rand(1, 4);
if($randomvar==1)
{
include("image or page url here");
}
else if($randomvar==2)
{
include("image or page url here");
}
else if($randomvar==3)
{
include("image or page url here");
}

else if($randomvar==4)
{
include("image or page url here");
}

?>

Sphere
03-31-2004, 02:22 AM
or this:

<?
$pic = rand(1, 4);
switch($pic)
{
case 4:
print("<img src=\"urhost\picsdir\$pic.extension\">");
break;
case 4:
print("<img src=\"urhost\picsdir\$pic.extension\">");
break;
case 3:
print("<img src=\"urhost\picsdir\$pic.extension\">");
break;
case 2:
print("<img src=\"urhost\picsdir\$pic.extension\">");
break;
default:
print("<img src=\"urhost\picsdir\$pic.extension\">");
}

?>

Sphere
03-31-2004, 02:52 AM
eh the threadstarter is the one who has copied a tutorial i just typed it and now its deleted :|
there goes 5 minutes of my time