@ligonsker you said:
The folders aren't actual filesystem folder
So you are storing all of these images in the database instead of storage? That is really not efficient.
But just suggestion to store the files in a folder and not in a table.
Also I am trying to understand what you are doing. All you need is a folder for a user that only that user has access to and in that folder store the images and thumbnails for that user.
You can have a relation set up to determine what other users has access to, and just example: billybob_127.
In the above billybob_127 is Billy Bob's folder.