implementing a file deletetion function
I have a system, where users (even public) can upload *.pdf files,now I want to implement a feature which provides the ability to delete the uploaded files.
This is what I have in mind :
- create an unique delete hash for each file and store it in database ( associate it with unique id of each file )
- Generate and display the delete url to the user who has uploaded the file
- When the delete url (Along with id and hash ) is called, check if the delete hash matches with the id
- unlink the file
is this system ok ? I just want to make sure the user can delete only 开发者_开发百科the file which he has uploaded , but not other files.
Thanks
Edit : Please suggest me a method to create a hash , which cannot be guessed .
If your users have to authenticate to use your service, it might be better to keep track of the file's owner and only allow that user to delete it. If all your users are anonymous the above solution should work ok. I would question how good an idea it would be to let anonymous users upload files though...
精彩评论