I am getting issue of my post data get truncated while internet speed is slow. In ajax I am passing base64 data of image and additional 2 fields for test purpose. In ajax file I have written code to print all POST data in file. When internet speed is normal its working fine and print all data of post in file. But if I change speed from Network panel to fast 3g / slow 3g then data truncates after some character. Please see below code and screenshot.
index.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
function getBase64(file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () {
var img = reader.result;
var data = {
'fname':"test",
'img':img,
'lname':"test1"
}
$.ajax({
url: "ajax.php",
data: data,
method: 'POST',
// timeout: 500000,
// contentType: "application/x-www-form-urlencoded",
}).done(function(result) {
console.log(result);
}).fail(function(jqXHR, textStatus, chk) {
console.log( "error" );
console.log( jqXHR );
console.log( textStatus );
console.log( chk );
});
};
reader.onerror = function (error) {
console.log('Error: ', error);
};
}
function submit_form() {
var file = document.querySelector('#files > input[type="file"]').files[0];
getBase64(file);
}
</script>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// var_dump(extension_loaded('suhosin'));
?>
<form id="files">
<input type="file" name="img">
<button type="button" id="submit" onclick="submit_form()">Submit</button>
</form>
ajax.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$myfile = fopen("check_response.txt", "w") or die("Unable to open file!");
$txt = json_encode($_POST);
fwrite($myfile, $txt);
fclose($myfile);
?>
</div>