The easiest way is to create a separate folder for each user and count the files in it to retrieve the number of images, then easily calculate the amount of available free slots. A nice function you can use to get a directory's contents is this
function GetDirFiles($directory){
$results = array();
$handler = opendir($directory);
while ($file = readdir($handler)) {
if ($file != "." && $file != "..") {
$results[] = $file;
}
}
closedir($handler);
return $results;
}