tags:

views:

97

answers:

3

We have a CMS where people can upload images. We currently don't offer a delete functionality, but it'd be nice to offer one. The problem with offering the delete functionality is that people might delete an image they don't need, but that same image might be used in someone else's article. Because people select the images with a WYSIWYG browser editor, we can not really easily track which image is used I think.

Anyone have a good solution on how to enable deletions without breaking other articles?

A: 

If you stored the image location in the database and the users picked from the database generated list you could add a reference count to the image record. Increment it when the image is added to the page, decrement it when it's removed.

Then on your image management pages only enable delete if the reference count is 0.

Though if the users can edit their own HTML there's nothing you can do to stop them (other than education) referencing images directly.

ChrisF
it's a good idea, the problem with it is, which I didn't have in my text I see, that people can edit the html and theoretically add images by copying the url into that..
Maarten
A: 

Although it really depends on how you've implemented your CMS solution, it is probably a good idea if you keep track of what articles are referencing your images. Then, whenever someones deletes the image from their article, you know to only delete the image file itself if you have zero references remaining.

skb
+1  A: 

A little analysis of the post data could possibly yield some image URIs, which you could use to modify the reference count (would work for direct edits too that way)?

As well as reference counting, if you don't do this already, you could ringfence the uploaded media on a per-user basis - thus if they delete something they think they don't need, it's not going to destroy other user's work?

Neither of these are particularly elegant ... but neither is the problem :P.