且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php message警告:在第0行的Unknown中,multipart / form-data POST数据中缺少边界

更新时间:2023-02-24 08:09:33

如果您避开,浏览器会设置正确的标题(包括Content-type中正确的多部分边界指示)不要手动指定任何东西。

The browser sets the correct headers (including the correct multipart boundary indication in the Content-type) if you haven't manually specified anything.

所以你需要做的就是删除以下行:

So all you need to do is remove the following line:

 hr.setRequestHeader("Content-type", "multipart/form-data");

否则你需要自己设置边界,正如Ellias Van Ootegem在使用XMLHttprequest上传文件 - 多部分/表格中缺少边界 - 数据

Otherwise you will need to set the boundary yourself as it is suggested by Ellias Van Ootegem in Uploading a file with XMLHttprequest - Missing boundary in multipart/form-data:

hr.setRequestHeader("Content-type","multipart/form-data; charset=utf-8; boundary=" + Math.random().toString().substr(2));