Link to home
Start Free TrialLog in
Avatar of lunatic359
lunatic359

asked on

problem with file structure and presentation

Hello members,

I just signed up, I've found this site to be useful not only to ask questions but to also help others.

This time around I do have a question.

I have a website that will incorprate email postcards. Everything works fine but I want to add a ranking system on the most popular postcards sent.

I already feel that I'm not making any sense.

Here is my file structure.

POSTCARDS : here i have the main postcard page and all category pages that displays the picture and the page that collects the user information to send the postcard. I also have a folder called "images" that holds the pictures

IMAGES : here i have subdirectories of every category (5). within those subdirectories are thumbnail and full size pictures marked ####.jpg and ####_tn.jpg respectfully.

CARDSTAT file : this file is where I store the ranks of every picture. one line from this file looks like the following:  ####.jpg,100

THE PROBLEM : For every card sent a cgi script runs to rewite the postcard's main page updating the 3 most popular pictures. I do have the picture's file name of those popular pictures but I can't find a way to locate which directory they are in.

IDEAS: code the cgi script to search for file name within all directories and retain the path in a variable when that file is found. or restructure the location of those directories. or instead of having just the picture's file name in the CARDSTAT file write out the path as well.

ANY SUGGESTIONS?

Thanks
Dan
Avatar of jmcg
jmcg
Flag of United States of America image

At the risk of suggesting "premature optimization", I think you want to avoid having your CGI script do an extensive search on every transaction. As your site gets busier, that could be a killer. I'd also start to be concerned about mutual exclusion issues on the updates.

That being said, the simplest solution for a low-volume site would be to fix the format of your CARDSTAT file so it included the pathname of each file instead of just the file name. A second alternative would be to create a separate FILELOC file that tied filenames to their proper directories.

Avatar of SegFault
SegFault

how about something like this?

set up a cron job to run once an hour or two hours or whatever.

have if start at your root image directory and find all the files. Then use that path and basename to do your mapping.

#!/usr/bin/perl
$toRoot = '/path/to/root/image/dir';

@files = `find $toRoot`;
%myFileMap;
open(OF, ">/path/to/imageMap/file.txt");

foreach $f (@files) {
  chop($f);

  $file = `basename $f`;
  $path = "$toRoot/$f";

  print OF "$file=$path\n";
}

close(OF)

Then, in your cgi, you can search the file for your lookup.
Avatar of lunatic359

ASKER

OK, I did find a way to locate the 3 most popular pictures' location. But now I'm considering what jmcq had stated about optimization. It is also a pain to type out all 150 pictures' path. So I guess I could write a cgi script that searches for these pictures once, write the paths in the CARDSTAT and then use the CARDSTAT to locate them. Does this sound more effiecent?

Thanks guys..
Avatar of wilcoxon
I have a couple of recommendations:

1) Include the path in the CARDSTAT file.  That looks to me to be the best solution.
2) Change CARDSTAT from a text file into some other format.  What you're doing would seem to fit one of the dbm file modules well (DB_File, GDBM_File, NDBM_File, SDBM_File, ODBM_File).  You should see a significant speedup in searching the file and [re]writing the file.
thanks wilcoxon I'll look into that dbm modules.. Never used one before... will i be able to edit one line within the db file?

ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wilcoxon,

thanks for the info, I'm not to keen on using hashes or dbm modules. I do have two questions for you though or anyone who would like to answer it.

Is there any good websites or books pertaining to this?

and would it be better to use PHP instead? (omiting learning curve).

Thanks
The first part of Ch 14 in _The Perl Cookbook_ covers the use of the various DBM modules.

On this particular aspect, PHP has no advantage over Perl. You might still prefer PHP overall for the project.
thanks again, I'll look into it...