weixin_33749131 2019-10-16 08:04 采纳率: 0%
浏览 41

PHP Ajax发布数据被截断

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);
?>

enter image description here

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 shape_predictor_68_face_landmarks.dat
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制