'The audio file was not uploaded successfully.')); exit; } // Get the file name and extension of the audio file $audio_name = $audio_file['name']; $audio_extension = pathinfo($audio_name, PATHINFO_EXTENSION); // Check if the audio file is a valid audio format if (!in_array($audio_extension, array('m4a', 'mp3', 'wav'))) { echo json_encode(array('status' => 'The audio file is not a valid format.')); exit; } // Generate a new filename using the passenger ID to avoid conflicts $new_filename = $audio_name . '.' . $audio_extension; // Move the audio file to the uploads directory with the new filename $target_dir = "audio_uploads/"; if (!is_dir($target_dir)) { mkdir($target_dir, 0755, true); // Create directory if it doesn't exist } $target_file = $target_dir . $new_filename; if (!move_uploaded_file($audio_file['tmp_name'], $target_file)) { error_log("Failed to move file to target directory: " . print_r($audio_file, true)); echo json_encode(array('status' => 'Failed to move the audio file.')); exit; } // Construct the link to the uploaded audio file $base_url = 'https://sefer.click/sefer/audio_uploads/'; // Replace with your actual domain $linkAudio = $base_url . $new_filename; // Respond with success and the audio file link echo json_encode(array('status' => 'Audio file uploaded successfully.', 'link' => $linkAudio)); // Close the database connection if it was established if (isset($conn)) { mysqli_close($conn); } ?>