[英]Trouble with sending .zip file on server with fetch()
I try to send my.zip file on server, this way:我尝试通过这种方式在服务器上发送 my.zip 文件:
function sendData(){
let zipFile = document.getElementById('fileReciever').files[0];
let formData = new FormData();
formData.append('id', btoa('7804044924'));
formData.append('data', zipFile);
fetch('http://localhost/xmlReader/reciever.php', {method: "POST", body: formData});
}
but on server (php) in $_POST i getting only "id" field, "data" is absent.但是在 $_POST 的服务器(php)上,我只得到“id”字段,“data”不存在。 What i am doing wrong?
我做错了什么?
i try this way:我尝试这种方式:
let zipFile = document.getElementById('fileReciever').files[0];
let formData = new FormData();
formData.append('id', btoa('7804044924'));
formData.append('data', zipFile);
//fetch('http://localhost/xmlReader/reciever.php', {method: "POST", body: formData});
let req = new XMLHttpRequest();
req.open("POST", 'http://localhost/xmlReader/reciever.php');
req.send(formData);
but result is same - on server in $_POST i getting only one field - "id", field "data" is absent.但结果是相同的 - 在 $_POST 的服务器上我只得到一个字段 - “id”,字段“data”不存在。
If you want to catch the files you have to use $_FILES instead of $_POST.如果要捕获文件,则必须使用 $_FILES 而不是 $_POST。
Let's say you sent an image than you var_dump($_FILES), you will get an array content假设您发送的图像比您的 var_dump($_FILES) 多,您将获得一个数组内容
and so you get your file-data.所以你得到你的文件数据。
Here you find good examples like the one i used here. 在这里你可以找到像我在这里使用的很好的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.