在用户创建时存储头像

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

Give the full path here

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

You have a problem with the path to where the image will be saved. Try using realpath() and dirname()

define('APPLICATION_PATH, realpath(dirname(__FILE__)));

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