luceos thanks for the reply. I tested it on a copy of my forum and since it was a dev version, I didn't dig too much into it. It will certainly be a pretty good functionality once it's stable and I appreciate it a lot, thanks 👍🏻
My concern is slightly different here. I need to have visibility on who uploads what and if I detect that somebody uses it for e.g. p*rn, and illegal stuff, I need to know who that is and ban him, etc. What you implemented is useful for cleaning up, it would delete the lingering files, true. However at that point it's already lost who uploaded that file. Furthermore, executing the command will completely remove the file, and if I haven't reviewed it, I would have missed that something illegal happened on the forum. I don't want that, I need to audit uploads and take measures.
If more people like my idea and are willing to sponsor it, it would be great if you can implement an interactive upload audit webpage that admin/mods can visit and have a look at all the uploaded files as a list, with proper previews of images, tracking who uploaded that image and punish him if needed, delete it (which would remove it both from the storage, and from the affected posts). I understand it's a complicated functionality, so if we are more people interested in that, please guys, let's sponsor @luceos to implement it 🍻
P.S. I know the commands you implemented will actually list the files when scanning but it's too difficult to follow, I will have to manually copy/paste URL-s to view them one by one... Still not clear who was the author, etc.
P.P.S. If I have to extend further, I think uploads on a forum should be completely public and visible to anybody. That's how it's implemented on some forums I've seen. People can upload files and pictures, but anybody can open the list of all the uploaded files/pictures in a forum and see who's the uploader, so that the functionality is not abused for illegal purposes like e.g. exchanging illegal content in private messages. Currently the uploaded files can even become lingering, so it's just a very convenient upload storage that is both publicly accessible and cannot be tracked to the uploader easily.