我必须首先创建Base64图像串并更新该字符串形式的脚本工作...
<form method="post" action="/process.php">
<input type="hidden" id="base64image" name="myimage" value="***base64 string gets updated here***" />
<input type="submit" value="Create Rotated Image" />
</form>
它再上岗的PHP脚本将其旋转90度,保持透明度,并将其保存为服务器上的png。
process.php ...
<?php
$data = str_replace("data:image/png;base64,","",$_POST["myimage"]);;
$data = base64_decode($data);
$degrees = 90;
$name = 'plate';
$im = imagecreatefromstring($data);
header('Content-Type: image/png');
imagealphablending($im, false);
imagesavealpha($im, true);
$rotation = imagerotate($im, $degrees, imageColorAllocateAlpha($im, 0, 0, 0, 127));
imagealphablending($rotation, false);
imagesavealpha($rotation, true);
imagepng($rotation);
$save = "*/root/my/image/directory/* image.png";
imagepng($rotation, $save);
imagedestroy($rotation);
imagedestroy($im);
?>
到目前为止好,这一切工作正常,它旋转并保存到服务器上,并显示在浏览器中的形象。
虽然现在我想发布到这个相同的脚本,但在后台运行它而不刷新页面。
所以我尝试这个...
<form method="post" action="/process.php">
<input type="hidden" id="base64image" name="myimage" value="" />
<input type="submit" value="Create Rotated Image" onclick="postimage();" />
</form>
<script>
$(document).ready(function() {
var mybase64image = $('#base64image').val();
function postimage() {
$.post("/process.php", {myimage:mybase64image});
};
});
</script>
但是,这已不再是图像保存到服务器上,任何人都可以看到我在做什么错在这里?
你在这里有什么代码:'*** base64 string gets updated here ***'? – Webeng
您需要防止默认表单提交。 – charlietfl
增加帖子请求主体的大小 – madalinivascu