the issue is code order.
the code for the delete record behavior comes before the code to delete the files.
to be able to trigger the record delete on the delete file success, the code to delete the file must come before the code to delete the record.
PHP Is processed from top to bottom.