Variables arn't expanded inside single quote strings.
You might want to see the difference in
echo '/var/www/html/test/img-gallery/$avatardirectory'
and
echo "/var/www/html/test/img-gallery/$avatardirectory"
Note that unlink() removes files, not directories. use rmdir() to remove (an empty) directory. (though it sounds like your $avatardirectory holds the name of a file, not a directory(?) )