我这里有一个swf文件,它将通过POST向PHP发送一个base64编码的文件。现在我通过$dataCode=file_get_contents("php://input");
我想要实现的是通过PHP将编码后的base64从swf转换为image并保存到特定的文件夹中。
这是我的代码,但在此期间,我只是将其剥离,看看imagecreatefromstring是否返回真值,并在页面上输出图像:
$dataCode = file_get_contents("php://input");
$dataCode = explode("=", $dataCode);
$data = $dataCode[1];
$imageData = rawurldecode($data);
$source = imagecreatefromstring($imageData);
if ($source !== false) {
header('Content-Type: image/png');
imagepng($source);
imagedestroy($source);
}
else {
echo 'An error occurred.';
}
然后,在这之后,我将把它保存到文件夹中,并通过XML输出图像的url。
类似这样的东西:
header("Content-Type:application/rss+xml");
echo '<?xml version='"1.0'"?>
<data>
<result status="1">
<url>'.$basepath.'converted.jpg'.'</url>
</result>
</data>';
ERROR是imagecreatefromstring返回错误值,如果遇到此问题,请提供帮助。我不知道是图像损坏了,还是我在这里做错了什么。任何建议或帮助都很棒。谢谢
在您的列表中,您已经使用rawurldecode()进行了解码。尝试使用base64_decode()