sanitize_file_name($_FILES['ar_woo_dae_custom_attachment']['name']), ); $boundary = wp_generate_password( 24 ); $headers = array( 'content-type' => 'multipart/form-data; boundary=' . $boundary ); $payload = ''; // First, add the standard POST fields: foreach ( $post_fields as $name => $value ) { $payload .= '--' . $boundary; $payload .= "\r\n"; $payload .= 'Content-Disposition: form-data; name="' . $name .'"' . "\r\n\r\n"; $payload .= $value; $payload .= "\r\n"; } // Upload the file $payload .= '--' . $boundary; $payload .= "\r\n"; $payload .= 'Content-Disposition: form-data; name="' . 'ar_dae_custom_attachment' . '"; filename="' . basename( sanitize_file_name($_FILES['ar_woo_dae_custom_attachment']['name']) ) . '"' . "\r\n"; $payload .= 'Content-Type: '.$_FILES['ar_woo_dae_custom_attachment']['type'].'' . "\r\n"; $payload .= "\r\n"; $payload .= file_get_contents( $local_file ); $payload .= "\r\n"; } $payload .= '--' . $boundary . '--'; $response = wp_remote_post( "http://199.229.252.211:8080/upload/image_save.php", array( 'headers' => $headers, 'body' => $payload, ) ); echo $response['body'];exit; } } /* When 2D model is selected and ready to convert to 3D model */ add_action('wp_ajax_ar_dae_response1', 'ar_woo_dae_process_request1'); function ar_woo_dae_process_request1() { $ar_woo_nonce = ($_POST['ar_woo_nonce']) ? $_POST['ar_woo_nonce'] : ""; $ar_woo_nonce = sanitize_text_field($ar_woo_nonce); if (!wp_verify_nonce($ar_woo_nonce, 'ar_woo_upload_model_file')) { die('security fail'); } else { $local_file = $_POST['ar_woo_dae_custom_attachment']; //path to a local file on your server // if ($local_file) { $filename = "file1.dae"; $post_fields = array( 'name' => sanitize_file_name($filename), ); $boundary = wp_generate_password(24); $headers = array( 'content-type' => 'multipart/form-data; boundary=' . $boundary ); $payload = ''; // First, add the standard POST fields: foreach ($post_fields as $name => $value) { $payload .= '--' . $boundary; $payload .= "\r\n"; $payload .= 'Content-Disposition: form-data; name="' . $name . '"' . "\r\n\r\n"; $payload .= $value; $payload .= "\r\n"; } // Upload the file $payload .= '--' . $boundary; $payload .= "\r\n"; $payload .= 'Content-Disposition: form-data; name="' . 'ar_dae_custom_attachment' . '"; filename="' . basename(sanitize_file_name($filename)) . '"' . "\r\n"; $payload .= 'Content-Type: application/octet-stream' . "\r\n"; $payload .= "\r\n"; $payload .= stripslashes($local_file); $payload .= "\r\n"; // } $payload .= '--' . $boundary . '--'; $response = wp_remote_post("http://199.229.252.211:8080/upload/image_save.php", array( 'headers' => $headers, 'body' => $payload, ) ); // echo "
"; print_r( $payload );
        echo $response['body'];
        exit;
    }
}
/* Ends */
?>