Gossamer Forum
Home : Products : DBMan : Customization :

lt gt problem with ID's and files

Quote Reply
lt gt problem with ID's and files
I have the multple upload mod on my database and the directory has has gotten so large that it takes forever if I need to FTP to the upload directory, so I'm attempting to split the upload directories up by 1000's. I've been successful so far up to a point. I can't seem to get the database to bring up a directory in the single or double digits (currently using 4 digits).

This is what I'm trying to do:

if (($form_upload_mod) && ($rec{$db_key} ge 1000) && ($rec{$db_key} lt 2000)) {
if (-e "$SAVE_DIRECTORY2/$rec{$db_key}") {
opendir (GRAPHIC, "$SAVE_DIRECTORY2/$rec{$db_key}") or &cgierr("unable to open directory: $SAVE_DIRECTORY2/$rec{$db_key}. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
++$num_files;
@stats = stat "$SAVE_DIRECTORY2/$rec{$db_key}/$file";
$prev_bytes +=$stats[7];
}
foreach $file (@files) {
next if ($file =~ /^\./); # Skip "." and ".." entries..
next if ($file =~ /^index/); # Skip index.htm type files..
print qq|<tr><td><$sizefont>Delete file</font>
<input type="checkbox" name="$file" value="delete"></td>
<td><img src= "$SAVE_DIRECTORY2_URL/$rec{$db_key}/$file"></td></tr>|;
}
}

that part of it works great as long as the ID number is between 1000 and 2000. But if I try to sort for anything under 1000 like this:

if (($form_upload_mod) && ($rec{$db_key} lt 1000)) {

I get nothing on any ID's less than 1000. For example, if I search for ID# 799, no files come up even though it's under 1000. If I change it to gt 5000, 799 will come up.
I don't know if this is a unix problem or perl problem with the way it sorts numbers, but is there a solution to this?
NOTE: I've tried this using the < sign in place of lt and it made no difference.
Thanks in advance!
Shannnon

Last edited by:

shann123: Feb 16, 2005, 11:29 PM
Quote Reply
Re: [shann123] lt gt problem with ID's and files In reply to
Not sure if it will help but check out this thread for some ideas:

Topic: Greater than - Less than "if" statement help
donm 25-Nov-2003
http://gossamer-threads.com/p/257174

I think I remember someone else having their files in various directories but I didn't find any reference to the thread in the FAQ. I do think it was Kellner that was helping someone find a solution.

Hope the above thread will help you find a solution.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [shann123] lt gt problem with ID's and files In reply to
I think the problem is because the system sees the numbers as:

1
111
20
234
55,687
62

I don't know if there is a way to tell the script this is a "number" not a character.

You could perhaps "pad" the numbers with leading zeros

0001
0111

etc.
Quote Reply
Re: [Watts] lt gt problem with ID's and files In reply to
I've got it figured out! Here's what I did:

Added:

if ($rec{$db_key} <= 99) {
$db_key_q = "00$rec{$db_key}";
}
if (($rec{$db_key} > 99) && ($rec{$db_key} <= 999)) {
$db_key_q = "0$rec{$db_key}";
}
if ($rec{$db_key} > 999) {
$db_key_q = "$rec{$db_key}";
}

above:

if (($form_upload_mod) && ($db_key_q <= 999)) {
if (-e "$SAVE_DIRECTORY/$rec{$db_key}") {
etc...
}
if (($form_upload_mod) && ($db_key_q > 999) && ($db_key_q <= 1999)) {
if (-e "$SAVE_DIRECTORY2/$rec{$db_key}") {
etc
}

This seems to work perfectly by adding the right number of 0's for the sorting part of it.
Now I can just start moving all of the directories to the right upload directories.. and get all of the coding done for every place that the images are called up. *sighs*
Thanks for your replies. :-)
Shannon