I want my module to delete all images that have been uploaded with its help and delete all database entries from 'file_managed' table on uninstall. I have no problem with the actual file deleting, but I'm stuck with database records deleting. I know there is a file_delete function that removes the database entry as well, but how is it possible to get the required fid then? Thanks in advance.

Comments

Stefan Lehmann’s picture

I think you should rather try to load the file by it's uri and then delete it via the file_delete() function. the file_delete() function will also physically remove the file.

That's a query I found in another comment somewhere:

$result = db_query('SELECT f.fid
              FROM {file_managed} f WHERE f.uri = :uri', array(':uri' => $uri));

So the only question / problem is to build the uri for a file, which should be straight-forwardish?

I like cookies!

NagareHoshi’s picture

Thank you very much for your help!