October CMS - Remove File Attachments With Unsaved Model

- 1 answer

I'm trying to create a front-end AJAX file uploader for a form and everything is working perfect, except for one issue.

I used deferred binding to enable uploading before the record is created in DB.

In a rare scenario, when someone uploads a file and doesn't send the form the record is not created, but the attached file still exists.

I don't know if there is a build-in solution for this problem is October CMS.

A better example is RainLab Blog Plugin. If you try a new post and add a featured image but not save the post and close the tab, the post doesn't create but the file remains in storage/app/uploads/public.

I was thinking of writing an scheduled task to delete unbinded files, but don't know how to detect them.

Does anyone have a solution for this issue?



you can look at the table:


and the ones without a attachment_id or/and attachment_type or/and field

are unused maybe the media table should be cleaned too.