Did you delete the images.txt file first? And I'm wondering about the path var. From what you've said it should likely be:
$path= "flags/";
Anyways, works fine here, and that version of PHP should support it.
Getting back to your question, I would use an associative array then, using the flag image filenames as keys with each value being the link you want associated with it, or you could just use the base name of the flag image file and give it a different extension to make the link. Assuming the pages you want to link to could easily be so named. Since I don't know that - Here's a simple associative array example along those lines (you would use the actual names of your flag files and the pages you want linked to each):
PHP Code:
<?php
$links = array("usflag.png" => "uspage.htm",
"ukflag.png" => "ukpage.htm");
print_r($links);
echo '<br>' . $links["ukflag.png"];
?>
Tested and works fine.
So then applied to you code:
Code:
<?php
$i=0;
$path="flags";
$ext = "png";
$extra= "alt=\"Random Image\" float=\"left\"";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (substr($file,strlen($file)-3,3)==$ext)
{ $imgs[$i++]=$file;
}
}
closedir($handle);
$today=getdate();
srand($today['mday']+$today['month']+$today['year']);
$r=rand(0,$i-1);
$links = array("usflag.png" => "uspage.htm",
"ukflag.png" => "ukpage.htm");
echo '<a href="' . $links[$imgs[$r]] . '">' .
"<img src=\"flags/{$imgs[$r]}\" alt=\"Photo\" /></a>
";
}
?>
As I say though, in the links array use the actual flag filenames and the actual page names you want associated with each one.
Note: This last bit I haven't tested, might contain typo(s). But will work if done as I've outlined. Hopefully you get the idea.
One more thing here about that other code we were working on, I'm like 99% sure it can work with your setup, so - since you did request it, perhaps we should keep trying to work it out - in that thread though, not here. You haven't addressed there the issues I asked you about, and there could be more things if you're willing to go through them there one at a time. Anything we do with links here should easily translate to that code.
Bookmarks