srs81 / CakePHP-AjaxMultiUpload

CakePHP 2 plugin to allow for easy multi-file upload with AJAX
Other
65 stars 33 forks source link

Preventing orphaned files on delete #5

Closed clarkritchie closed 12 years ago

clarkritchie commented 12 years ago

This is a nice looking plugin, and I'm hoping to use it.

Deleting files on the edit view works great, but what if a user deletes an object that has files attached -- is there any way to trap this so any attached files can also be removed from the filesystem? Otherwise they are orphaned.

Thanks!

srs81 commented 12 years ago

Excellent point! I can't think of a way to handle it in the plugin, this might have to be handled in the delete() function of the controller.

One way I can think of is to expose a function that returns the directory name - or even a delete() function that deletes the files directory for that specific object directly. Do you have any suggestions on the best method?

I'll try to release a new version soon that includes this function.

clarkritchie commented 12 years ago

That's basically what I was thinking - you'd have to call a method from the object's controller on delete. I don't know enough about Cake to intelligently suggest how, from your controller, you get back a list of associated files that you could then iterate through, deleting one by one, or at least warn the user that files associated with that object will be deleted.

I'm really hoping to use this plugin, I've played around with a few ways to do file uploads in the last day or two and this was by far the easiest to implement -- and has the easiest to use features, namely drag-drop, and multi-file support.

srs81 commented 12 years ago

OK, I'll try to have this feature over the coming week and let you know as soon as its done.

srs81 commented 12 years ago

Fixed in latest release (v 1.0.3.) :)

Please check. Note that you will need to add the plugin component to any existing component to get this to work (or you can follow the docs for a new app.)