This topic maybe sound familiar but im not quite pleased with any of the Stackoverflow questions that are asked. See I´m creating a website with a small amount of members, say somewhere around 50. And I have created my registration form and my login form. But now I wan´t to assign a avatar to each new registered member. When i new member successfully register, a random avatar saved on the server will be assigned to them. The user will carry this avatar with them at every visit. So to clear my question:
How can I assign a random picture to each new user and save the picture to their user_id
?
I'm currently using a MySQL and coding in PHP. I have a "Select-random-picture" function, but not sure how to store a picture with a user. I'm happy for any kind of advice.
EDIT
After some considerations, I have been able to state a clearer goal.
I'm having images stored in a file system that i want to assign randomly to new members, AND when the image has been assign, it should be "taken". So if a new user register he will get a random image without the possibility to getting a already taken image.
I have only succeded in creating a generator that uploads random images, but not assuring that the same picture won't come again:
$avatarDir = 'members/images/avatars/';
$pics= glob($avatarDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomPics = $pics[array_rand($pics)];
$query_new_user_picture = $this->connection->query("INSERT INTO my_images (image) VALUES('$randomPics')");
$results = mysql_query($query_new_user_picture);