如何在php中为图像创建表单imagepng生成随机名称?

如何在php中为图像创建表单imagepng生成随机名称?,php,image,Php,Image,我试图生成一个图像,我成功地使用了这段代码 imagepng($image, 'generated.png'); 但是我希望image generated.png name的名称是一些随机字符串。 所以我试着这样做 $name = random; imagepng($image, $name.'.png'); 但它不起作用。尝试使用PHP: 注意:添加了时间函数以使名称唯一。我正在使用类似的功能: // make a unique filename for the uploaded file

我试图生成一个图像,我成功地使用了这段代码

imagepng($image, 'generated.png');
但是我希望image generated.png name的名称是一些随机字符串。 所以我试着这样做

$name = random;
imagepng($image, $name.'.png');
但它不起作用。

尝试使用PHP:


注意:添加了时间函数以使名称唯一。

我正在使用类似的功能:

// 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++;
}

谷歌搜索中的第一个链接:见uniquid函数:我已经做了,但是这个错误。警告:imagepngxxx.png:无法打开流:C:\wamp\www\project1\u temp\test\all\outputing-Copy.php在线中的参数无效xxx@ceyeong因为你没有这个名字的图像,所以你需要先制作图像。不,我已经创建了图像,当我做类似的事情时它会工作。imagepng$image,'name.png';但是我希望name.png是随机的,所以我尝试创建随机字符串并将其存储在$name变量中。我尝试了imagpng$image,$name.'.png';但现在它不起作用了名称是唯一的,目录是完全空的。但每当我将文件名指定为变量时,就会出现错误。比如$name=Rand1100;imagepng$image,$name.'.png';但是当它像这个imagepng$image,'name.png'时,它就工作了;开始一个新的问题,描述你尝试了什么。
// 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++;
}