如何创建和使用PHP从一个base64 EN codeD数据/串保存图像到网站上的文件夹
问题描述:
我有以下的code。关于我的PHP文件,该文件是工作的罚款,其解码的base64字符串,并显示出作为在网页上的形象,但我希望它保存的文件夹得上。
I have the following code on my php file which is working fine, Its decoding a base64 string and showing that as a image on the webpage, but i want it to save it on a folder too.
<?php
$base = $_POST['encoded'];
$base = base64_decode($base);
$im = imagecreatefromstring($base);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
?>
我已经尝试这些链接中描述的解决方案,但这些都不是为我工作
i have already tried the solution described on these links but none of these are worked for me
How保存PNG图像服务器端,从一个base64数据串
How从创建的base64 GD图像连接codeD JPEG?
这将是code的额外的行可能此图像保存到文件夹
what will be the extra line of code which could save this image to a folder
答
该文件的权限未设置为写模式。它设置为777,并具有以下code测试。
The file permissions was not set to writing mode. set it to 777 and tested with the following code.
<?php
$base = $_POST['encoded'];
$base = base64_decode($base);
$im = imagecreatefromstring($base);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im,'image.png'); // saving image to the same directory
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
?>