Gossamer Forum
Home : Products : DBMan : Customization :

external text file

Quote Reply
external text file
i'm using the external text file mod but don't want the file to be mandatory. if someone has entered text that has been written to the external file, but later deletes the text when modifying the record, i cannot get the program to delete the external file. i tried using the code in the sub delete part of the mod in the modify part of db.cgi:

Code:


if ($in{'text'}) {
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;
}
else {
unlink "$save_text_dir/$data[$db_key_pos].txt";
}

i thought if there was no $in{'text'} because the existing text was erased, that this unlink command would delete the related file, but it doesn't work. can someone pls point me in the right direction? thanks.
Quote Reply
Re: [delicia] external text file In reply to
ah, i figured it out as soon as i clicked post. don't know why i didn't notice before but the filename is different in the two sections. the following change works:


if ($in{'text'}) {
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;
}
else {
unlink "$save_text_dir/$in{$db_key}.txt"; # changed filename here
}