The order would be the upload code and then the insert or update into the database.
How you would limit it would depend on the database structure and user experience you want to support.
You could insert a new row into a related table for each image and add a recordset to determine how many rows they have already inserted and then don't allow another insert once they reach 12 with server validation... but there are a lot of other ways you could do it depending on how you wanted it to work.