简体   繁体   中英

html2canvas cannot convert and upload 1mb < size image in php server

I am using html2canvas div to images converted, then images post to php, this process is only executed below 700kb images only, 700kb < size images cannot post in php. Please give some ideas and sample code.

my html code is:

<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>

my query:

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 code is:

$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'];

php.inipost_max_size的值设置为大于1 MB,

post_max_size="4M"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM