Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

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
0
lunatic359
Asked:
lunatic359
  • 4
  • 2
  • 2
  • +1
1 Solution
 
jmcgOwnerCommented:
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.

0
 
SegFaultCommented:
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.
0
 
lunatic359Author Commented:
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..
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
wilcoxonCommented:
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.
0
 
lunatic359Author Commented:
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?

0
 
wilcoxonCommented:
Basically, the way the dbm modules work is you tie a hash to the file and the file stores (in a fast binary format) the hash.  So, once you do the tie line, you treat it just like a normal (simple) hash (eg $tied_hash{###.jpg} = 100 will save the value 100 to the file for ###.jpg).  If you need more than a scalar value in your hash, then you need to use MLDBM.  Let me know if you have more questions on all the dbm modules.
0
 
lunatic359Author Commented:
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
0
 
jmcgOwnerCommented:
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.
0
 
lunatic359Author Commented:
thanks again, I'll look into it...
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now