Gossamer Forum
Home : Products : DBMan : Customization :

How to Delete an associated file

Quote Reply
How to Delete an associated file
 
suppose i have a field in my database that is associated to a file, when i delete that record, how would i delete the file associated to it?
your help will be greatly appreciated.
Quote Reply
Re: How to Delete an associated file In reply to
You're using the file upload mod, right?

There's a section in the mod where you would edit sub delete_record to delete a file that has the same name as the record:

Code:
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) {
$ALLOWED_EXT =~ s/\\.//g;
$ALLOWED_EXT =~ s/\$//g;
@extensions = split (/\Q|\E/o,$ALLOWED_EXT);
foreach $extension (@extensions) {
(-e "$SAVE_DIRECTORY/$data[$db_key_pos].$extension") &&
(unlink "$SAVE_DIRECTORY/$data[$db_key_pos].$extension")
}
}
}
else { $output .= $line . "\n"; }

Instead of the above, use

Code:
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_DIRECTORY/$data[5]";
}
else { $output .= $line . "\n"; }

This, of course, assumes that $SAVE_DIRECTORY holds the path to your file directory and that the field with your filename is field 5. Make changes as appropriate.


------------------
JPD