[thelist] php image rotation problem

php architect phparch at gmail.com
Mon Mar 14 23:26:16 CST 2005


Your file might have blank lines in it. Maybe try.

$fp = file($file);
foreach($fp as $k=>$line){
 if( ! $line ){
   unset($fp[$k]);
 }
}

Also you could change 

$random_image = $fp[array_rand($fp)];

to

$key = array_rand($fp);
$random_image = $fp[$key];
echo($key);

That will at least tell you what line is being selected, if you
believe the problem is with an image.


On Mon, 14 Mar 2005 17:02:51 -0500, Bruce Gilbert <webguync at gmail.com> wrote:
> I am using the following php image rotation script.
> 
> <?php
> #random images example
> #this is your file
> $file = "rotating-images.txt";
> #open the file
> $fp = file($file);
> #generate a random number
> srand((double)microtime()*1000000);
> #get one of the entries in the file
> $random_image = $fp[array_rand($fp)];
> #display the entry
> echo "<img src='$random_image'></img>";
> ?>
> 
> in my rotating-images.txt file I have my list of images named
> image1.jpg, image2.jpg through image7.jpg all on a separate line.
> 
> the problem I am having Is a get a blank broken image every third or
> so rotation and I can't debug to see which image is not displaying,
> because I am calling it through <?php acquire and right
> clicking/properties doesn't tell me anything.
> 
> all the images are on the server, and in the same file as the
> rotating-images.txt
> 
> any ideas to what may be going on?
> --
> ::Bruce::
> --
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


More information about the thelist mailing list