PHP base64编码不同的结果

标签 php mysql base64

我有一个将图像转换为 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/

相关文章:

php - 如何对 MySQL 中多列的值求和?

php - 如何更改数据库行位置并维护 php 和 mysql 中的顺序

javascript - 问题 - Base 64 PDF 字符串未在 IE 11 中呈现

java - 如何用jsp源构建base64图像src?

php - parse_signed_request - base64_url_decode - strstr 使用

php - 是否可以直接在 PHP 对象上使用 XPath?

php - PDO 类中的调用值

mysql - 如何将远程 ASP 站点与站点的本地副本同步?

java hibernate - 如何将日期列映射为日期时间?

mysql - 我如何判断 'state' 的最后 x 行是否 = 1