Are you not using a database?
If no:
Set up a database to store the users, then create a logical connection between the iamges and the users.
for instance
Users:
|---------------------------------------
| UserId Username Password |
|---------------------------------------
| 1 Robert 3j9745t3 |
| 2 Paul 03945u30 |
|---------------------------------------
Images:
|--------------------------------------------------
| ImageID UserId Desc ImageHash |
|-------------------------------------------------|
| 1 1 Some Desc 87ytr8d23yr|
| 2 1 Some Desc 5uty4095u40|
|-------------------------------------------------|
Then store the images on your images directory like 87ytr8d23yr.png
and then you can do a php query like so
$userid = 1;
$sql = "SELECT * FROM Images WHERE UserId = " . (int) $userid . " ORDER BY ImageID LIMIT 10";
if(false !== ($resource = mysql_query($sql)))
{
while($imageRow = mysql_fetch_object($resource))
{
if(file_exists('imageDir/' . $imageRow->ImageHash . '.png'))
{
//Do whatever.
}else
{
//Delete the row and inform the user that the picture has been deleted for some reason.
}
}
}
Also you just have to do a Comments table and add ImageId, and when a user comments on an image just add the image into the comment row so you can trace it.