[eluser]Teks[/eluser]
Your algorithm for retrieving an existing file should be something like this:
1) retrieve the entry from the database (including file location on the server)
2) check that file actually exists on the server:
--a) file exists on the server: move on to step 3
--b) file does not exist on the server - warn the user, and perhaps give option to:
----i) upload a replacement file (exit and go to 'upload file' function)
----ii) delete record from database (and exit)
3) retrieve and display/download/present the file to the user
So, if you think about it, it would make sense for your delete algorithm to be something like this:
1) check that file exists on server:
-- a) if file does not exist on server (record in database is bogus) - skip to step 2
-- b) if file exists:
----i) try to delete file from server:
------A) success - move to step 2
------B) fail to delete - abort everything
2) delete record from database.
Even if you experience a problem with the final operation (=deleting the file record from the database), this will be picked up by your 'retrieving' algorithm next time a user tries to access the file.
Short answer: delete file first, record second.