Search code examples
phpgravatar

storing avatar on user creation


I have a random image generated by php (monsterid) and I want to store it on my server upon user registration, but the following gives me an error:

$url = 'http://www.example.com/admin/monsterid/monsterid.php';
$monsterimg = '/admin/monsterid/monsters/'.$timestamp.rand(0,999).'.png';
file_put_contents($monsterimg, file_get_contents($url));

Error =

Warning: file_put_contents(/admin/monsterid/monsters/efefef990.png) [function.file-put-contents]: failed to open stream: No such file or directory in /home/example/public_html/admin/register.php on line 35


Solution

  • Give the full path here

    $monsterimg = '/some/path/admin/monsterid/monsters/'.$timestamp.rand(0,999).'.png';