Delete files using wildcard

I am using the file upload SC action and storing the file as record_id.ext (eg. 2.jpg) so the files are tidy. The action retains the uploaded extension (.jpg or .png for example) and renames the first part to the record id.

If someone uploads image.jpg (which saves as 2.jpg) and then re-uploads another.png (which saves as 2.png) I end up with two files - 2.jpg and 2.png. The database stores the filename so there’s no problem with the functionality but I have an orphaned file of 2.jpg.

So, I’m thinking that deleting id.* (eg. 2.) before doing the upload would keep everything tidy. But it’s not working! I get a 500 error saying 2. isn’t found.

Can anyone help with this?

Community Page
Last updated: