a Pdf file to an Api...I have problem with the body actually working in the php code...I want to send the pdf file as json encoded to the api adress but it says not able to handle request...the code works without adding the body...kindly check and see if I am doing something wrong. Thanks in advance.  <?php
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  
                  $request = "https.....xxxxx; //
                  
                  
                  
                  
                  
                  $headers = array(
                  
                  
                    "Authorization: Bearer xxxxxxxxx",
                  
                  
                     //'cache-control => no-cache',
                  
                  
                     //'content-type => multipart/form-data',
                  
                  
                    "Content-Type: application/json", 
                  
                  
                     "Accept: application/json",
                  
                  
                  );
                  
                  
                  
                  
                  
                  $body = array(
                  
                  
                     //"voucher_data": "base64_encode("frmUpload")",
                  
                  
                    "voucher_data":  base64_encode(file_get_contents($_FILES["frmUpload"]["tmp_name"]));
                  
                  
                    "callback_url":  "http://xxxxxxx",
                  
                  
                  );
                  
                  
                  
                  
                  
                  $ch = curl_init();
                  
                  
                  curl_setopt($ch, CURLOPT_URL, $request);
                  
                  
                  curl_setopt($ch,CURLOPT_HTTPHEADER,array($headers));
                  
                  
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  
                  
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                  
                  
                  curl_setopt($ch, CURLOPT_POSTFIELDS, array($body)); 
                  
                  
                  //curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                  
                  
                  curl_setopt($ch, CURLOPT_POST, true);
                  
                  
                  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
                  
                  
                  $results= curl_exec($ch);
                  
                  
                  
                  
                  
                  
                  
                  
                  if(isset($_FILES['file'])){
                  
                  
                     $errors= array();
                  
                  
                     $file_name = $_FILES['file']['name'];
                  
                  
                     $file_size =$_FILES['file']['size'];
                  
                  
                     $file_tmp =$_FILES['file']['tmp_name'];
                  
                  
                     $file_type=$_FILES['file']['type'];
                  
                  
                     $file_ext=strtolower(end(explode('.',$_FILES['file']['name'])));
                  
                  
                     
                  
                  
                     $extensions= array("jpeg","jpg","png","pdf");
                  
                  
                     
                  
                  
                     if(in_array($file_ext,$extensions)=== false){
                  
                  
                        $errors[]="extension not allowed, please choose a Pdf file.";
                  
                  
                     }
                  
                  
                     
                  
                  
                     if($file_size >= 4097152){
                  
                  
                        $errors[]='File size must not be greater than 3MB';
                  
                  
                     }
                  
                  
                     
                  
                  
                     if(empty($errors)==true){
                  
                  
                        move_uploaded_file($file_tmp,"files/".$file_name);
                  
                  
                        echo "Success";
                  
                  
                     }else{
                  
                  
                        print_r($errors);
                  
                  
                     }
                  
                  
                  }
                  
                  
                  
                  
                  
                  
                  
                  
                  ?>
                  
                  
                
how do you initiate the $body array?
Обсуждают сегодня