是这样的,今天按着网上的资料写了一个PHP生成验证码的模板:
可是我不想让他直接输出图片,而是以base64输出图片,请问该如何做?自己试了很多方法都不成功,除非必须这样:
$img_file = 'https://www.xxxxxxxxxx.com/authcode.php';
$img_info = getimagesize($img_file);
$img_src = "data:{$img_info['mime']};base64," . base64_encode(file_get_contents($img_file));
echo "
";
请问如何在getCode中就直接输出base64呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
是否直接输出图片关键在于
关闭 header
imagepng函数, 第二个参数设置图片保存位置.
然后去读取存储位置读取图片, 转换成base64.
php文档
文档下面的留言部分可能有你需要的答案