@Freund להלן קוד שעובד להעלאת קובץ:
<?php
$url = "https://www.call2all.co.il/ym/api/UploadFile";
// Prepare multipart form data
$data = [
"token" => "$username:$password",
"path" => "ivr2:14/test.wav",
"file" => new CURLFile("audio/test.wav", "audio/wav", "test.wav") // File upload
];
// Make the request
$response = curl_post_request($url, $data);
echo "Response: " . $response;
# POST request helper function
function curl_post_request(string $url, $data, array $headers = [])
{
// Initialize cURL
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // Multipart data
// Set headers (DO NOT manually set Content-Type for multipart)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Execute request
$response = curl_exec($ch);
// Handle errors
if (curl_errno($ch)) {
throw new Exception(curl_error($ch));
} else {
return $response;
}
}