View previous topic :: View next topic |
Author |
Message |
soulm8sflyff -
Joined: 18 Feb 2006 Posts: 52
|
Posted: Wed Mar 22, 2006 7:36 am Post subject: random image |
|
|
Ok, I want to make a script that displays a random image everytime you refresh.
I used this php script:
Code: | <?php
$random = "random.txt";
$fp = file($random);
srand((double)microtime()*1000000);
$rl = $fp[array_rand($fp)];
echo $rl;
?> |
and made this random.txt file:
Code: | <a href="activitiesrafting.jpg"><img src="activitiesrafting.jpg" border="0"></a>
<a href="activitiessnorkeling.jpg"><img src="activitiessnorkeling.jpg" border="0"></a>
<a href="abel.jpg"><img src="abel.jpg" border="0"></a>
<a href="aboutmain.jpg"><img src="aboutmain.jpg" border="0"></a>
<a href="abtbrgys.jpg"><img src="abtbrgys.jpg" border="0"></a>
<a href="abtgeninfo.jpg"><img src="abtgeninfo.jpg" border="0"></a>
<a href="abthistory.jpg"><img src="abthistory.jpg" border="0"></a>
<a href="abtofficials.jpg"><img src="abtofficials.jpg" border="0"></a>
<a href="abtprojects.jpg"><img src="abtprojects.jpg" border="0"></a>
<a href="abtvision.jpg"><img src="abtvision.jpg" border="0"></a>
<a href="activitiesanimalpetting.jpg"><img src="activitiesanimalpetting.jpg" border="0"></a>
<a href="activitiesboating.jpg""><img src="activitiesboating.jpg" border="0"></a>
<a href="activitiesfishing.jpg"><img src="activitiesfishing.jpg" border="0"></a>
<a href="activitieshiking.jpg"><img src="activitieshiking.jpg" border="0"></a>
<a href="attractionsbanaoangbr.jpg"><img src="attractionsbanaoangbr.jpg" border="0"></a>
<a href="attractionsbarasibis.jpg"><img src="attractionsbarasibis.jpg" border="0"></a>
<a href="attractionsbeach.jpg"><img src="attractionsbeach.jpg" border="0"></a>
<a href="attractionsheroespark.jpg"><img src="attractionsheroespark.jpg" border="0"></a>
<a href="attractionsimeldapark.jpg"><img src="attractionsimeldapark.jpg" border="0"></a>
<a href="attractionsjesusisland.jpg"><img src="attractionsjesusisland.jpg" border="0"></a>
<a href="attractionsrocks.jpg"><img src="attractionsrocks.jpg" border="0"></a>
<a href="attractionsviewdeck.jpg"><img src="attractionsviewdeck.jpg" border="0"></a>
<a href="attractionszigzag.jpg"><img src="attractionszigzag.jpg" border="0"></a>
<a href="basketry.jpg"><img src="basketry.jpg" border="0"></a>
<a href="blacksmith.gif"><img src="blacksmith.jpg" border="0"></a>
<a href="broiler.jpg"><img src="broiler.jpg" border="0"></a>
<a href="delicaciescrabs.jpg"><img src="delicaciescrabs.jpg" border="0"></a>
<a href="delicaciesgrapes.jpg"><img src="delicaciesgrapes.jpg" border="0"></a>
<a href="delicaciesipon2.jpg"><img src="delicaciesipon2.jpg" border="0"></a>
<a href="delicaciesoyster.jpg"><img src="delicaciesoyster.jpg" border="0"></a>
<a href="delicaciestuna.jpg"><img src="delicaciestuna.jpg" border="0"></a>
<a href="duckegg.jpg"><img src="duckegg.jpg" border="0"></a>
<a href="egglayers.jpg"><img src="egglayers.jpg" border="0"></a>
<a href="hollowblocks.jpg"><img src="hollowblocks.jpg" border="0"></a>
<a href="itik.jpg"><img src="itik.jpg" border="0"></a>
<a href="quarrying.jpg"><img src="quarrying.jpg" border="0"></a>
<a href="tourismactivities.jpg"><img src="tourismactivities.jpg" border="0"></a>
<a href="tourismattractions.jpg"><img src="tourismattractions.jpg" border="0"></a>
<a href="tourismdelicacies.jpg"><img src="tourismdelicacies.jpg" border="0"></a>
<a href="tourismfiestas.jpg"><img src="tourismfiestas.jpg" border="0"></a> |
It works when I browse it at:
http://www.flyff-soulm8s.cykit.net/Santa/pics/random.php
But when I try to put a link in my page for the random image to display, I used this code:
Code: | <img src="http://flyff-soulm8s.cykit.net/Santa/pics/random.php"> |
Cause I googled it and that's what it says.
But It Doesn't Work. Please help. Thanks. _________________ "It is better to have only two ideas and one of them is wrong, than to have loads of right ideas but NONE OF THEM ARE YOURS!" - Soul
Last edited by soulm8sflyff on Thu Mar 23, 2006 12:43 pm; edited 1 time in total |
|
Back to top |
|
 |
eznetlinks -
Joined: 27 Sep 2003 Posts: 144
|
Posted: Wed Mar 22, 2006 2:28 pm Post subject: |
|
|
I don't know why it doesn't work, I shortened the php and it works for me.
Code: |
<?
$fp = file("random.txt");
echo $fp[array_rand($fp)];
?>
|
|
|
Back to top |
|
 |
soulm8sflyff -
Joined: 18 Feb 2006 Posts: 52
|
Posted: Wed Mar 22, 2006 2:34 pm Post subject: |
|
|
Ok this is the first time Google screwed up! Well, it's not really Google's fault but the site where I saw the tutorial for this sucks a lot! I changed the code for the link from:
[code]<img src="http://flyff-soulm8s.cykit.net/Santa/pics/random.php">[code]
to:
[code]<?php include("http://www.flyff-soulm8s.cykit.net/pics/random.php"[/code]
And now it works. And:
eznetlinks wrote: | I don't know why it doesn't work, I shortened the php and it works for me.
[code]
<?
$fp = file("random.txt");
echo $fp[array_rand($fp)];
?>
[/code] |
With the code you said, yes that works fine, the problem comes when I try to link that to my pages. But well, I figured it out now.[/code] _________________ "It is better to have only two ideas and one of them is wrong, than to have loads of right ideas but NONE OF THEM ARE YOURS!" - Soul |
|
Back to top |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Wed Mar 22, 2006 2:38 pm Post subject: Re: Random Image Every Refresh |
|
|
soulm8sflyff wrote: | But when I try to put a link in my page for the random image to display, I used this code:
Code: | <img src="http://flyff-soulm8s.cykit.net/Santa/pics/random.php"> |
|
If you do that, the src argument of img will reference a HTML page and will not render the image.
So instead of doing that, simply include the PHP file:
Code: | <?php include "random.php"; ?> |
You can also do the same with SSI pages by using the #include directive. _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
 |
soulm8sflyff -
Joined: 18 Feb 2006 Posts: 52
|
Posted: Wed Mar 22, 2006 2:43 pm Post subject: |
|
|
Yes I figured that out now. The tutorial sucks. It says whn you want to link it, you just do it like a normal image and use <img src=. . . .> Stupid tutorial! I'm glad it's ok now. thanks for the replies anyway. _________________ "It is better to have only two ideas and one of them is wrong, than to have loads of right ideas but NONE OF THEM ARE YOURS!" - Soul |
|
Back to top |
|
 |
|