我正在使用 html2canvas 生成图像,我想将其保存在服务器上。当我尝试这样做时,我在控制台中收到错误 413 Request entity too large并且图像未保存。一切都可以在本地主机上运行,但不能在实时服务器上运行。
我已经用谷歌搜索了 2 天如何解决这个问题,我的 php.ini 和 .htaccess 配置正确,所以我很确定那不是问题。
HTML:
<button onclick="fb()">Save</button>
JavaScript:
<script language="javascript">
function fb(){
var w= <?php echo $resolution['width'] ;?>;
var h= <?php echo $resolution['height'] ;?>;
$("#picture").show();
html2canvas($('#picture'), {
width: w,
height: h
}).then(function(canvas) {
var imgData = canvas.toDataURL('image/png');
var url = 'export.php';
$.ajax({
type: "POST",
url: url,
dataType: 'text',
data: {
base64data : imgData,
}
});
})}
</script>
PHP:
<?php
$data = $_REQUEST['base64data'];
$image = explode('base64,',$data);
file_put_contents('../public/image/myImage.png', base64_decode($image[1]));
?>