<?php
// Handle file upload
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $target_dir = "../sadam/";
  $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);

  // Send photo via WhatsApp Business API
  $phone_number = "966502393250"; // Replace with recipient's phone number
  $photo_url = "../sadam/" . basename($_FILES["fileToUpload"]["name"]);
  
  /*$curl = curl_init();
  curl_setopt_array($curl, array(
    CURLOPT_URL => "https://hiwhats.com/API/send",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode(array(
      "phone" => $phone_number,
      "body" => "",
      "filename" => $photo_url,
      "caption" => "Check out my photo!"
    )),
    CURLOPT_HTTPHEADER => array(
      "Content-Type: application/json"
    )
  ));*/
  
  $m="966502393250";
      $s= $photo_url;
      $data["mobile"]="966568884014";
      $data["password"]="Compre123";
      $data["instanceid"]="19862";
      $data["numbers"]=$m;
      $data["type"]="1";
      $data["message"]=$s;
      $data["json"]="1";
      
      
      $timeout = 10;
      
      $ch = curl_init();    
      curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );     
      curl_setopt( $ch, CURLOPT_URL, "https://hiwhats.com/API/send" );     
      curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );     
      curl_setopt( $ch, CURLOPT_ENCODING, "" );     
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );     
      curl_setopt( $ch, CURLOPT_AUTOREFERER, true );     
      curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );    # required for https urls     
      curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );  
      if(!empty($data) && is_array($data)){
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
      }
      curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );    
      curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );     
      curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );     
      $response=curl_exec($ch);
  
  //$response = curl_exec($curl);
  //curl_close($curl);
  
  echo "Photo sent!";
}
?>

<form method="post" enctype="multipart/form-data">
  Select photo to upload:
  <input type="file" name="fileToUpload" id="fileToUpload">
  <input type="submit" value="Upload and send" name="submit">
</form>