random image (strange)
Posted: Tue Jan 13, 2004 3:34 pm
hi,
I am making a script to have a random image each time a page loads. I managed to create it like this:
it works but i want it to be diplayed when i call it like this:
I tried :
but i can't figure out the good way.
Any ideas??
I am making a script to have a random image each time a page loads. I managed to create it like this:
Code: Select all
<?php
if (isset($op))
{
srand((double)microtime()*1000000);
$directory=opendir('./');
$pics=array();
while ($file = readdir($directory))
{
if (!is_dir($file))
{
$pics[]=$file;
}
}
closedir($directory);
$random_nums=array_rand($pics,2);
$final=$pics[$random_nums['0']];
echo "<img src="$final">";
}
?>Code: Select all
<img src="rndimg.php">Code: Select all
<?php
header("Content-type: image/gif");
header("filename=$final");
?>Any ideas??