Can somebody help me create a script that checks for images in a "secure" folder (not in public_html) then populates a mySQL database based on the file name?

e.g. /home/gaming/products/product1 contains the following files:


and I would like the script to insert the following information to the mySQL database:

id | key | product_name | file_name
1 | 8DHSJR49GJ6MS8FJ4BA6H39DH | product1 | pro1_1.jpg
2 | 083BFY9294TF7WN34UYSWBD3S | product1 | pro2_2_.jpg
3 | F834IHF934HF8934RHF9308J8 | product1 | pro1_3.jpg

the random_generated_code must be unique, 25 characters long and include numbers and letters.

Thanks for your help.