PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
basdog22
Forum Contributor
Posts: 158 Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece
Post
by basdog22 » 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:
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">";
}
?>
it works but i want it to be diplayed when i call it like this:
I tried :
Code: Select all
<?php
header("Content-type: image/gif");
header("filename=$final");
?>
but i can't figure out the good way.
Any ideas??
uberpolak
Forum Contributor
Posts: 261 Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar
Post
by uberpolak » Tue Jan 13, 2004 3:56 pm
I would use
Code: Select all
<?php
header('Location: ' . $final);
?>
EDIT: What I mean is, use that code in place of the echo command.
basdog22
Forum Contributor
Posts: 158 Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece
Post
by basdog22 » Tue Jan 13, 2004 4:08 pm
uberpolak
Forum Contributor
Posts: 261 Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar
Post
by uberpolak » Tue Jan 13, 2004 4:24 pm
No, geology rocks. You're welcome.
Nay
Forum Regular
Posts: 951 Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia
Post
by Nay » Tue Jan 13, 2004 11:50 pm
Another way is also:
Code: Select all
header("Content-type: image/gif");
readfile($final);
-Nay