html2canvas无法转换和上传1mb< php服务器中的大小图像

时间:2016-09-15 05:20:23

标签: javascript php jquery html2canvas

我正在使用html2canvas div来转换图像,然后将图像发布到php,此过程仅在700kb图像下执行,700kb<大小图片无法在php中发布。请提供一些想法和示例代码。

我的HTML代码是:

<div id="popup_div">
    <h1>i put some special</h1>
</div>
<form method="POST" enctype="multipart/form-data" action="work_cards.php" id="myForm">
     <input type="hidden" name="img_val" id="img_val" value="" />
</form>

我的疑问:

function capture() {
    $('#popup_div').html2canvas({
        useCORS: true,
        allowTaint: true,
        onrendered: function (canvas) {
            //Set hidden field's value to image data (base-64 string)
            $('#img_val').val(canvas.toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream"));
            //Submit the form manually
            document.getElementById("myForm").submit();
        }
    });
}

work_cards.php代码是:

$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
$url = "Kings_design";
//Save the image
file_put_contents('img/order/'.$url.'.jpeg', $unencodedData);
echo $_POST['img_val'];

1 个答案:

答案 0 :(得分:0)

post_max_sizephp.ini的值设置为大于1 MB,

post_max_size="4M"