You need to create an array of the files names within the loop that processes the images and then outside of that loop submit the record to the database once with the array being written to the ‘attached’ field.
Is there a reason you want it all in one row? Is it not easier to manage in separate rows? If you want to delete a single row/image it will be easier separately.
I’d agree, will make it very difficult to deal with later on. As they seem to be email attachments, though, it might not matter that removing one in the future will be much more complex than a simple query if they were stored in a separate table. As well as that, you need to have a much larger column size to cope with the maximum possible number of attachments that might be stored against a single mail, though I might be showiing my roots there in worrying about disk usage.
If you’re dead set on doing it in a single column, I’d modify the loop to keep appending the new filename to your list of filenames, then use that composite variable to call the query. Though maybe as @Noppy said above, you could build an array instead.