Gossamer Forum
Home : Products : DBMan : Customization :

Need some advise.......

Quote Reply
Need some advise.......
Hi everyone,

I'm building a database with in each records some text data but also a certain number of pictures.
The amount of pictures is different for each record (between 0 to 12 or more)

Is there a way to let the script check in a certain directory how much pictures there are and build a nice table with it automaticly.

Right now I have a field in the database with the number of pictures. If above mentioned is not possible can I use this number to build a table with it? (Always two columns wide)

I hope this all sounds clear.

Jeroen
Quote Reply
Re: Need some advise....... In reply to
Not knowing how your directories are set up, I can't be sure how this would go. But I can tell you how I would set it up.

Have your graphic directories all contained in one main directory--
Code:
<graphics>
<record1graphics>
<record2graphics>
etc.

Then define the path to the main graphics directory. Unless the graphics directory is within the dbman directory, you'll need to define the path to the graphics directory. (I always get confused using relative paths, so I use the whole path.) Also you'll need to define the URL to the graphics directory.

$graphics_path = "/path/to/graphics/directory";
$graphics_url = "http://www.server.com/graphics/directory";

Then you can use them like this--

Code:
opendir(DIR,"$graphics_path/$rec{'Directory'}");
@files = readdir(DIR);
closedir(DIR);
$i = 2;
print "<TABLE>";
while ($i < scalar(@files)) {
if ($i%2 == 1) { print "<TR>"; }
print qq|<TD><img src="$graphics_url/$files[$i]"></TD>"|;
if ($i%2 == 0) { print "</TR>"; }
++$i;
}
if ($i%2 == 0) { print "</TR>"; }
print "</TABLE>";

There is no error checking in this routine, so if the directory doesn't exist or if there are files in the directory that aren't image files or if there are subdirectories, you'll run into problems. However, I did try out the routine and at least I know the Perl code works! Smile



------------------
JPD