Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Re-attaching Files without writing new entry.

Quote Reply
Re-attaching Files without writing new entry.
Anyone know if there's a good way to prevent the entry from being rewritten to the Attach database if the file already exists?

For example.

Say I have an image called myimage.jpg, and I upload, but realize that the image needs to be modified and reuploaded. When I reupload the image, it replaces the old image, but it rights a new entry to the database, so then I have two entries with the same filename, but only one image in the directory and if I try to get rid of the second entry, it removes the image.

There's no check in sub attach_file to see if the image is already there:

$query = qq~
INSERT INTO $table (ID, DataID, ServerName, FileName, FileType, FileSize)
VALUES (?, $data_id, "$data_id.fil", $fn, $ft, $size)
~;

This one is beyond me.

Thanks for any help.

Peace.

Kyle
Quote Reply
Re: Re-attaching Files without writing new entry. In reply to
Hmm, there isn't an easy way, because the program doesn't care about the filename, it doesn't consider it a duplicate (as you can attach multiple files with the same name).

What you would want to do is something like:

DELETE FROM Links_Attach
WHERE DataID = yourlinkid AND
FileName = 'yourfilename'

run that and it will remove the first entry (or do nothing if one didn't exist). Then do an insert as normal.

Sorry about the late reply!

Alex