我正在将一个xhr base64编码的字符串从JavaScript发送到php文件。在php中我获取内容并将其放在一个文件中:
<?php
$img = trim($_POST["base64"]);
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
file_put_contents('image.png', $data);
echo 'image.png';
?>
如何创建唯一的文件名,而不是image.png中的file_put_contents,将其设置为/ tmp文件夹并返回唯一的URL?
谢谢你。