random... list... mess.

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

Post Reply
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

random... list... mess.

Post by Daisy Cutter »

okay i have a list of random images and urls right now. it's huge so I put it's source at:

http://kafene.org/randimgsrc.txt

I want to do this:
keep the array for the random images.
Change the if/else business to a corresponding array so that they match up
generate a list of all these images (so that rather than being random, they all just dump into the form <a href="$url"><img src="$img" alt="img" />

OR what I think is easier AND better:
take the contents of an entire directory, make the images named like imagename.com.png and then randomly get one, put it in the form <a href="http://www. $imagename - .png"><img src="$imagename" alt="img" /></a>...

If you can just give an example for either I should be able to work from there.

EDIT:
the directory listing I would want in that format is http://kafene.org/img/ .
i realize i would have to change the filenames.
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

ok i've been thinking about this...

for the second one where I got a plain directory listing and used it almost like a flat file database:

I could use a for loop and this code:

Code: Select all

<?php
if ($handle = opendir('/home/mcovey/kafene.org/img')) {
   echo "Directory handle: $handle\n";
   echo "Files:\n";

   while (false !== ($file = readdir($handle))) { 
       echo "$file\n";
   }

   closedir($handle); 
}
?>
and then use something like sed (but in PHP) to search for and output results...
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

can anyone help me here?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd use a database table to store the url/image location information.
Daisy Cutter
Forum Commoner
Posts: 75
Joined: Sun Aug 01, 2004 9:51 am

Post by Daisy Cutter »

feyd wrote:I'd use a database table to store the url/image location information.
hm.. that just seems so big for what i'm doing. Is there any way to use sed through PHP? In that case the rest would be fairly simple, otherwise I'll just stick with using my array and conditionals.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can always just have a flat file of the linkage information concerning the known files in the folder. You'll have to verify that the files still exist each time you open the file, in case one gets deleted.
Post Reply