<?php
$json = file_get_contents('php://input');
$obj = json_decode($json);

//error_log("\n" . date('Y-m-d H:i:s') . " Incoming Request :\n $json ", 3, $destination);

$filename = $obj->{'filename'};
$audiod = $obj->{'audiod'};
$api_key = $obj->{'api_key'};

$filePath = $filename;

// The API endpoint to send the file to
$apiUrl = 'https://mbeyalishe.or.tz/test2.php';

// Initialize cURL
$ch = curl_init($apiUrl);

// Prepare the file for upload
$cfile = new CURLFile($filePath, 'audio/wav', 'audiofile.wav');

// Prepare POST data
$postData = [
    'file' => $cfile,    // This is the file being sent
    'some_field' => 'some_value', // Any other form data you want to include
];

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: multipart/form-data'
]);

// Execute the request
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo 'Response: ' . $response;
}

// Close cURL
curl_close($ch);




echo "";