我有一个将图像转换为 Base64 的 php 脚本。在本地运行一切都很好,它会解码并显示,但是当我通过curl post将其发送到mysql时,它会生成一个不同的字符串。前 1/4 的字符串匹配,然后全部改变。我已经搜索了几个小时,但仍然不知道是否有人可以提供帮助?
$newImg = "Path to image";
$imgBinary = fread(fopen($newImg, "r"), filesize($newImg));
$imgString = base64_encode($imgBinary);
$string = "FName=SName= etc etc etc Photo=".$imgString;
$url ="Url to web service";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
$phpArray = json_decode($output, true);
curl_close ($ch);
最佳答案
$string 必须使用 urlencode php 函数进行 urlencode
关于PHP base64编码不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24127635/