1

I am trying to post a image file and some data using php curl

Following is my code:

if(isset($_POST['imageupload'])){
    $username='dsfsdfds';
        $password='8bi8sldjfldsjflkjdsb';
    $boundary = uniqid();
    $delimiter = '-------------' . $boundary;
    $headers = array(
        "Content-type: maultipart/form-data; charset=utf-8; boundary=$delimiter",
    );
    $ch = curl_init();
        $data = array('image' => curl_file_create($_FILES["image"]["tmp_name"], $_FILES['image']['type'], $_FILES['image']['name']),'test' => 'true','username'=>$username, 'password'=>$password);             

        curl_setopt($ch, CURLOPT_URL, 'https://skldfjsd.com/api/v1/images');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);



    $server_output = curl_exec($ch);

    curl_close ($ch);
    $info = curl_getinfo($ch);
    print_r($info);
    if (curl_error($ch)) {
        $error_msg = curl_error($ch);
        echo 'error occured';
        echo $error_msg;
    }
        echo 'normal output';
    var_dump($server_output);
}

Following is the error message I am getting

For request 'POST /api/v1/images' [Unexpected end of input]

Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77

0 Answers0