<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $product_name = $_POST['product_name'];
    $product_description = $_POST['product_description'];
    $product_category = $_POST['product_category'];
    $product_image_path = $_FILES['product_image']['tmp_name'];
    $save_path = "/home/u749097869/domains/ragubim.com/public_html/wp-content/uploads/woocommerce_uploads/"; // Adjust the save path as needed

    // Handle the file upload for the product image
    if (move_uploaded_file($_FILES['product_image']['tmp_name'], $save_path . $_FILES['product_image']['name'])) {
        echo "Product image uploaded successfully.";
    } else {
        echo "Failed to upload product image.";
    }

    // Connect to the backend server using cURL
    $url = '/home/u749097869/domains/ragubim.com/public_html/wp-content/uploads/woocommerce_uploads/fwXGDScGKyaTiv8abqJeoP0EQZl6xOSL-GeoLite2-Country.mmdb'; // Replace with your backend server URL
    $data = array(
        'product_name' => $product_name,
        'product_description' => $product_description,
        'product_category' => $product_category,
        'product_image' => new CURLFile($save_path . $_FILES['product_image']['name'])
    );

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);

    // Handle the response from the backend server
    if ($response) {
        echo "Form data sent to the backend server successfully.";
    } else {
        echo "Failed to send form data to the backend server.";
    }
}
?>