st512
It’s not that simple unfortunately. We deduplicate attachments. Meaning a single file can be attached to many different things. So when deleting a file (especially images) you need to ensure they are not attached to anything else or you will receive errors for eternity. You would need to check thread entry bodies, faq bodies, canned response bodies, etc. to ensure they aren’t inline anywhere.
Once you have determined there are no other references you can delete the related _attachment record, delete the _file record, then delete the file on the file system. You could simply let it be handled automatically by the system. Let’s say a thread has an attachment and that attachment only exists there. When you delete the ticket the system will mark the file as orphaned (not attached to anything) and it will be deleted after 24 hours via cron cleanup scripts.
Cheers.