如何在fetch中传递图像并将其保存在php动作中以将t上传到服务器?

时间:2018-01-13 11:39:10

标签: php react-native

如何在本机和php中上传和处理图像?

React-native code:

let img = new FormData();
img.append('file', {
    filename: 'image.jpg',
    filepath: this.state.image.uri,
    contentType: 'image/jpeg', 
});    

Fetch(`action url?f=createComplaint&otp_code=${this.props.OTPInputText}&cp_phone_no=${this.props.phno}&cp_relationship=${this.props.Relationship}&cp_name=${this.props.Name}&cp_email_id=${this.props.email}
                        &cp_address=${this.props.address}&cp_complaint_type=${this.props.complianttype}&cp_district=${this.props.location}&cp_compliant_details=${this.props.summary}&otp_code=${this.props.OTPInputText}&cp_resp_name=${this.props.RName}&cp_resp_phone_no=${this.props.Rphno}&cp_resp_email_id=${this.props.Remail}&cp_resp_address=${this.props.address}&cd_name=${this.state.CName}
                     &cd_gender=${this.state.cGender}+&cd_age=${this.state.cAge}&cd_indentification=${this.state.cIDMark}&cd_photo=${img}`)

PHP代码:

if(isset($_POST)){
    $addphoto= explode(".",basename($_FILES['cd_photo']['name']));
    $cd_photo = date('Ymdhis').rand(0,999).".".$addphoto[1];
    $pathPhoto = '../child_photos/'.$cd_photo;

    if(move_uploaded_file($_FILES['cd_photo']['tmp_name'], $pathPhoto)) {

    }

我在我的网址中获取了[object][object] img

0 个答案:

没有答案
相关问题