如何在php中生成图像reated form imagepng的随机名称? [重复]

This question already has an answer here:

I am trying to generate a image and i am successfull using this code.

imagepng($image, 'generated.png');

but I want the name of image generated.png name to be some random string. So I tried like this

$name = random;
imagepng($image, $name.'.png');

but it does not work..

</div>

Try the rand function of PHP:

$name = rand(1,100);
$name = $name.time();

imagepng($image, $name.'.png');

Note: Added time() function to make the name unique.

I am using something similar:

// make a unique filename for the uploaded file and check it is not already
// taken... if it is already taken keep trying until we find a vacant one
// sample filename: 1140732936-filename.jpg
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]  ['name']))
{
  $now++;
}