Javascript 如何获得客户端帖子的大小?

Javascript 如何获得客户端帖子的大小?,javascript,php,handsontable,Javascript,Php,Handsontable,我想问的是,如何获得作为客户端传递给服务器的数据的大小。在开发应用程序时,我无法获得服务器端的全部数据。我在服务器端的POST限制大小是6M,如php.ini文件所示 我之前也问过类似的问题(),但没有得到及时的回答 谢谢试试这个: $data_size = (int) $_SERVER['CONTENT_LENGTH']; 请在提交表单上使用此功能 <button onclick="store()" type="button">form submit</button>

我想问的是,如何获得作为客户端传递给服务器的数据的大小。在开发应用程序时,我无法获得服务器端的全部数据。我在服务器端的POST限制大小是6M,如php.ini文件所示

我之前也问过类似的问题(),但没有得到及时的回答

谢谢

试试这个:

$data_size = (int) $_SERVER['CONTENT_LENGTH'];

请在提交表单上使用此功能

<button onclick="store()" type="button">form submit</button>

function store(){     
    var totalsize = 0;    // total post data size
    $('form').find('input[type=file]').each(function() { // for all files in form
        totalsize += this.files[0].size;
    });

    totalsize=totalsize+($("form").not("[type='file']").serialize().length);

    if (totalsize > (6 * 1048576)) { // > 6MB   
        // this will exceed post_max_size PHP setting, now handle...

        alert('this will exceed post_max_size PHP setting')
    } else if ($('form').find('input[type=file]').length >= 10) { // max_file_upload_limit = 10; 
        // if file upload is more than 10
         alert('upload is more than 10 files')
    }else{

      you are free upload data successfully
    }
}
表单提交
函数存储({
var totalsize=0;//post数据的总大小
$('form').find('input[type=file]')).each(function(){//用于表单中的所有文件
totalsize+=此.files[0]。大小;
});
totalsize=totalsize+($(“form”).not(“[type='file']”)。serialize().length);
如果(总大小>(6*1048576)){/>6MB
//这将超过post_max_size PHP设置,现在处理。。。
警报('这将超过post_max_size PHP设置')
}如果($('form').find('input[type=file]').length>=10){//max\u file\u upload\u limit=10;
//如果文件上载超过10
警报('上载超过10个文件')
}否则{
您已成功免费上传数据
}
}

然后将我的(int)$\u服务器['CONTENT\u LENGTH']=3598和php.ini中的post\u max\u size=6M的post limit size增加到22m。那么,我没有得到我正在解析的完整数据是否合理呢?您没有描述问题(即什么东西不工作),而是您对其根本原因的假设。来吧,说出来:这怎么不起作用,你怎么断言错误的行为。它不起作用,因为当我提醒我发送到服务器的数据字符串时,我可以看到我发送的所有内容。但是在服务器端,当我提醒制造商,即数据字符串的最后一个键值对时,我得到了,但是我没有得到$all_数据,它包含用户输入的前端handsontable行中的数据。使用它,我得到3598,max_post_size=6M,那么我不应该面对这个问题?我没有上传文件,而是handsontable行。请看我的这个问题