文件上传反应本机到PHP服务器

时间:2018-03-14 07:57:52

标签: php ios reactjs react-native file-upload

我正在react-native-ios中实现文件上传, 这是我在react-native js上的代码:

const formData = new FormData();
formData.append('photo', { uri: image.sourceURL, name: image.filename, type: 'image/jpeg' });
// here is my formdata console :{uri: "file:///Users/.../DCIM/100APPLE/IMG_0002.JPG", name: "IMG_0002.JPG", type: "image/jpeg"}
fetch('services.php?action=MultiplefileUpload',{
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
      'Accept': 'application/json'
    },
    body: formData
  }).then((response) => response.json())
  .then((responseJson) => {
     console.log(responseJson);
  })
  .catch((error) => {
    console.error(error);
  });

在php页面上我写道:return $_FILES 回复是:photo: {name: "IMG_0002.JPG", type: "", tmp_name: "", error: 1, size: 0}

我的代码在哪里做错了?我也阅读了这个链接:Upload image file to php server from react-native

0 个答案:

没有答案
相关问题