Gossamer Forum
Home : Products : DBMan : Customization :

Single file upload mod - Internal Server Error

Quote Reply
Single file upload mod - Internal Server Error
Got basic database installed and working fine. Installed single file upload mod. Got it working, but not properly (for some reason it didn't upload the files at all (the upload folder was empty), though sometimes it looked like it had worked... Then it would display only one image with all records, and when modified, the image got lost... very strange). Looked through forum and FAQ, found people with similar problem, made suggested changes to code. Ended up with a 500 Internal Server Error. Have neglected to make backups. :/

Can anyone help? Everything is uploaded in ASCII and CHMODed correctly.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
When you have a problem with a mod it's best to go over the instructions again and be sure you have followed all the changes called for :)

You didn't say whether you were requiring users to upload an image or not.

In your sub add_record within the .cgi file you are missing the portion

IN sub add_record
If you *DO NOT* want to require all users to upload a file when they add a record, *AND* you have added the 'Graphic' field to your field definitions, AFTER THE LINE YOU ADDED ABOVE, add :
##############################################
opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
$in{'Graphic'} = 'Yes';
$graphic_found=1;
}
}
unless ($graphic_found) { $in{'Graphic'} = ''; }


You also don't have the changes to sub modify_record in your db.cgi file:

opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
$in{'Graphic'} = 'Yes';
$graphic_found=1;
}
}
unless ($graphic_found) { $in{'Graphic'} = ''; }

In sub delete_records - you are missing a } which would cause errors within the script:

if ($delete_list{$data[$db_key_pos]}) { # if this id is one we want to delete
$delete_list{$data[$db_key_pos]} = 0; # then mark it deleted and don't print it to the new database.

if ($db_upload) {
opendir (GRAPHIC, "$SAVE_DIRECTORY") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
unlink ("$SAVE_DIRECTORY/$file");
}
}
}
}
else { $output .= $line . "\n";
}

####### end replacements for file upload ###########
}

foreach $key (keys %delete_list) {

Hope this gets you up and running.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Single file upload mod - Internal Server Error In reply to
Hi, thanks for your reply. I did double-check the instructions and made sure I got everything right (but apparently something went wrong after I made the changes suggested in the forum/faq). Maybe I misunderstood one of the instructions. I don't want to require the users to upload an image. However, this one says:

Quote:
"If you *DO NOT* want to require all users to upload a file when they add a record, *AND* you have added the 'Graphic' field to your field definitions"

As I don't have the 'Graphic' field, I was under the impression that I don't need this part. Do I need it anyway? Do I have to add the 'Graphic' field? I thought it was an optional thing.

I added the missing } but I still get the server error, so I guess it has to do with the other missing portions. It confuses me, though, since I got it working before without adding the 'Graphic' part.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
...

Hello? Anyone still reading this?
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
I've always used the mod with the graphic field included whether or not I was requiring a user to upload a graphic.

I would think that it would be necessary to have the sections within the db.cgi file so that it will locate the graphics when both adding and modifying records.

Usually when an error occurs it's due to mismatched } with the sub delete_records.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Single file upload mod - Internal Server Error In reply to
Ok, I made all the changes you told me, and I'm still getting an Internal Server Error. (I uploaded in ASCII and everything in CHMODed correctly). What am I doing wrong? Maybe there is another missing } but I can't find any. I've attached the modified files again. I appreciate any help.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
Are you able to access your server error logs?

If not, in the FAQ noted below under the section "Troubleshooting" there is a snippet of code in the thread "Debugging - How To Obtain Useful Error Messages" which you can add to your DBMan files so it will catch any errors and display them in a .txt file on your server.

When you added the graphic field did you also modify the .db file to include the extra field? Did you include this field in your html.pl sub html_record_form?

I think from the FAQ you can also find a script for locating missing brackets.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Single file upload mod - Internal Server Error In reply to
Yes, I have access to the error logs. It says "Premature end of script headers" for db.cgi. Does this mean there is a missing } ?

I didn't modify the .db file. It's empty, since there aren't any records in the database. I thought I didn't need to modify the .db file at all, since it only holds the records and is updated automatically.

If you mean the .cfg file, I did add the new field to that one (see attachment).

I added the code from the mod in html.pl as it said in the instructions (the "### Wherever you want your graphic to print out, use the following" thing). I haven't changed anything about it since I first uploaded the attachment in the first post.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
BTW, I tried to get the script for finding missing brackets, but both of the links in the FAQ were down.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
I fixed the links to brackets.zip it can also be directly accessed using this url

http://redundantcartridge.com/dbman/brackets.zip

I'm not sure that is your problem though. I really think if you follow my suggestions as to using the snippet of code to help get useful error messages it will help you track down the problem. I use this all the time and it saves hours of debugging time.

It also helps to move the

$db_debug = 1;

line up in your .cfg file to above the section:
# File and URL's

so it will catch any errors within the .cfg file.

Also when you added the Graphic field to your .cfg file you didn't add it to your add_form sub.

When glancing over your files I also noticed you didn't compare what you had with the sections of coding I provided above which has the latest updates for the file upload mod.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/

Last edited by:

LoisC: Sep 28, 2003, 9:38 AM
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
You have a little syntax error in db.cgi around line 227:

Code:
($output .= ''$line\n'' and next LINE)
if ($restricted and ($db_userid ne $data[$auth_user_field]));

You have two single quotes around your scalar and it should be a double quote on each side. See if that helps.

~Charlie
Quote Reply
Re: [Chaz] Single file upload mod - Internal Server Error In reply to
I got it working now. I think it was the syntax error Charlie mentioned. Must have copy-pasted it from somewhere without noticing.

Thanks for your help both of you!

I now have a different problem, though. I'm not sure if I should open a new thread or not. The problem is this:

When I added my first record, I could upload a new picture without problems and it displayed just fine. Then I added a second record, and the picture for the first record was gone. When I FTP'd to the upload directory, it turned out the first picture was gone and only the second picture was there. The same happened for the third record I added. It seems the newly uploaded image just replaces the one that is already there. How can I fix this?
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
Check to be sure that the following is in sub html_record:

$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
print qq|<img src= "$SAVE_DIRECTORY_URL/$file">|;
$graphic_found=1;
}
}

Look over the sections of code I provided in a post above as they provide the latest fixes. Not sure if you went back and made those changes, but pehaps that will fix the problem.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Single file upload mod - Internal Server Error In reply to
Yes, I made all those changes. I'm still having the same problem. The only thing I didn't change is the "useful error messages" one, since I feared I'd mess something up. Should I do it anyway?

I've attached the files again, in their newest version... I hope I didn't miss anything.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
Please recheck again the codes I provided above for the changes to your db.cgi file.

You still don't have the latest changes in your copy of the files as I provided above.

For instance the line:

$file_test = $in{$db_key} . ".";

is what is most likely causing your problems, it needs to be

$file_test = $rec{$db_key};

in both those subs.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Single file upload mod - Internal Server Error In reply to
You are right, the changes you provided were not there. This is strange, as I know for a fact that I did change them when you first mentioned it. I have no clue why they suddenly were back to the old version. Maybe something got accidentally replaced. I feel dumb now. :-(

Anyway, I have now made the changes in sub add_record, delete_records, and modify_record, but I still have the same problem. Anything else I need to change?

I'm sorry to be such a nuisance, but I don't know enough about programming to search for the error myself. :-( I really appreciate your efforts.
Quote Reply
Re: [alhena] Single file upload mod - Internal Server Error In reply to
For every field you have defined within your .cfg file you should also have each field listed in your sub html_record_form (whether visible or hidden). Glancing at your html.pl file you don't have the 'Graphic' field listed.

Once you add this field you will most likely need to adjust your database to add this field or start with a fresh .db file.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Single file upload mod - Internal Server Error In reply to
It's working, it's working! :)

I added the 'Graphic' field to sub html_record_form, but it still wasn't working. Then I did a search through the cgi file and discovered that there was a

if ($file =~ /^$file_test/) {

in sub validate_upload. I decided I had nothing to lose and changed it to

if ($file =~ /^$file_test\./) {

and tried it. Apparently that was what had caused the error. The first version was that way in the original mod I downloaded (same for the modify_record and add_record). I'm not sure if I'm the only who had problems like this. But if it's a general thing, shouldn't it be fixed?

I tested the database a bit and so far everything seems to be working fine now. Let's hope there won't be any more errors popping up later. Thanks a lot for your help, LoisC!

Now off to install the relational database mod... Wish me luck. :)