##################################################################### # External Text File Mod # by JPDeni # Last Modified: 21 May 2000 ##################################################################### # The purpose of this mod is to allow you to save an external text # file at the same time you add a record to your database. This comes # in very handy if you want to have large amounts of text, but you # don't want your .db file to be filled up too quickly. # # Note that you will not be able to search for text within the .txt # file, but only for text that is in the .db file itself. I would # suggest that you add a field to your database for keywords that # people might search for. Just be sure that you do *not* name your # keyword field 'keyword'. Name it anything else. # # You can put any html formatting you wish to in the textarea and it # will print out correctly. ##################################################################### # Create a directory. It can either be within your dbman directory # or outside of it. The only limitation is that it must be on the # same server as DBMan. # # Set the permissions of this directory to 777. # Define a variable in your .cfg file with the *path* to your text # file directory. $save_text_dir = '/path/to/text/file/directory'; #Not a URL! No trailing slash!! # Add a textarea field to sub html_record_form and call it text. # (Just make sure you do *not* have a field called "text" defined in # your .cfg file.) # You can change the dimensions of the text file as you wish. ##################################################################### # In db.cgi, sub add_record, after close DB; # automatically removes file lock # add open (TEXT, ">$save_text_dir/$in{$db_key}.txt") or &cgierr("error in add_record. unable to open text file $save_text_dir/$in{$db_key}.txt\nReason: $!"); print TEXT $in{'text'}; close TEXT; ##################################################################### # In db.cgi, sub modify_record, after close DB; # add open (TEXT, ">$save_text_dir/$in{$db_key}.txt") or &cgierr("error in modify_record. unable to open text file $save_text_dir/$in{$db_key}.txt\nReason: $!"); print TEXT $in{'text'}; close TEXT; ##################################################################### # In db.cgi, sub delete_records, if you have not previously made a # change to this subroutine, change $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. ($output .= $line . "\n"); # otherwise print it. # to 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. unlink "$save_text_dir/$data[$db_key_pos].txt"; } else { $output .= $line . "\n"; # otherwise print it. } # If you have already made changes to this portion of sub # delete_records (such as with the file upload mod), after $delete_list{$data[$db_key_pos]} = 0; # add unlink "$save_text_dir/$data[$db_key_pos].txt"; ##################################################################### # In html.pl, at the beginning of the subroutine for the display # where you want to print out the .txt file, (sub html_record or # sub html_record_long, if you're using the short/long display mod) # after my (%rec) = @_; # add $rec{$db_key} =~ s///g; open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in displaying record. unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!"); @text = ; close TEXT; $rec{'text'} = join "",@text; # You can then use the variable $rec{'text'} anywhere within the # subroutine that you want your text to print ##################################################################### # In html.pl, sub html_record_form, after my (%rec) = @_; # add if ($in{'modify'}) { open (TEXT, "<$save_text_dir/$rec{$db_key}.txt") or &cgierr("error in html_record_form. unable to open text file $save_text_dir/$rec{$db_key}.txt\nReason: $!"); @text = ; close TEXT; $in{'text'} = join "",@text; } #####################################################################