source/php/OAuth/OAuthRequests.php
public function submitImage()
    {
        if (! isset($_FILES['file'])) {
            wp_send_json_error(__('Image is not selected, please try again.', 'event-integration'), 'event-integration');
        }

        $endPoint             = '/media';
        $consumerKey          = get_option('_event_client');
        $consumerSecret       = get_option('_event_secret');
        $accessToken          = get_option('_event_token');
        $accessTokenSecret    = get_option('_event_token_secret');
        $oauthVersion         = "1.0";
        $apiUrl               = rtrim(get_field('event_api_url', 'option'), '/');
        $apiResourceUrl       = $apiUrl . $endPoint;
        $nonce                = md5(mt_rand());
        $oauthSignatureMethod = "HMAC-SHA1";
        $oauthTimestamp       = time();

        // Create multipart content body. Holds media to be uploaded
        $eol = "\r\n";
        define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));
        $fileContents = file_get_contents($_FILES['file']['tmp_name']);
        $content =  "--" . MULTIPART_BOUNDARY . $eol .
                    "Content-Disposition: form-data; name=\"file\"; filename=\"".rawurlencode($_FILES['file']['name'])."\"". $eol .
                    "Content-Type: " . $_FILES['file']['type']. $eol . $eol .
                    $fileContents . $eol;
        $content .= "--" . MULTIPART_BOUNDARY . "--" . $eol;

        $sigBase = "POST&" . rawurlencode($apiResourceUrl) . "&"
            . rawurlencode("oauth_consumer_key=" . rawurlencode($consumerKey)
            . "&oauth_nonce=" . rawurlencode($nonce)
            . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
            . "&oauth_timestamp=" . $oauthTimestamp
            . "&oauth_token=" . rawurlencode($accessToken)
            . "&oauth_version=" . rawurlencode($oauthVersion)
         );
        $sigKey = rawurlencode($consumerSecret) . "&" . rawurlencode($accessTokenSecret);
        $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
        $authHeader = "OAuth oauth_consumer_key=" . rawurlencode($consumerKey) . ","
            . "oauth_nonce=" . rawurlencode($nonce) . ","
            . "oauth_signature_method=" . rawurlencode($oauthSignatureMethod) . ","
            . "oauth_signature=" . rawurlencode($oauthSig) . ","
            . "oauth_timestamp=". rawurlencode($oauthTimestamp) . ","
            . "oauth_token=" . rawurlencode($accessToken) . ","
            . "oauth_version=" . rawurlencode($oauthVersion);

        $context = stream_context_create(array(
            "http" => array(
                'method' => 'POST',
                'header' => 'Content-Type: multipart/form-data; boundary=' . MULTIPART_BOUNDARY . $eol
                            . "Content-Disposition: attachment filename=\"" . rawurlencode($_FILES['file']['name']) . "\"\r\n"
                            . "Authorization: " . $authHeader . $eol,
                        'content' => $content
            ),
            'ssl' => array(
                'verify_peer' => defined('DEV_MODE') && DEV_MODE === true ? false : true,
                'verify_peer_name' => defined('DEV_MODE') && DEV_MODE === true ? false : true
            )));

        $result = file_get_contents($apiResourceUrl, false, $context);

        if ($result === false) {
            wp_send_json_error(__('Something went wrong uploading your image', 'event-integration'));
        }

        // return uploaded media id
        $resObj = json_decode($result);
        wp_send_json_success($resObj->id);
    }
public function submitImage()
    {
        if (! isset($_FILES['file'])) {
            wp_send_json_error(__('Image is not selected, please try again.', 'event-integration'), 'event-integration');
        }

        $endPoint             = '/media';
        $consumerKey          = get_option('_event_client');
        $consumerSecret       = get_option('_event_secret');
        $accessToken          = get_option('_event_token');
        $accessTokenSecret    = get_option('_event_token_secret');
        $oauthVersion         = "1.0";
        $apiUrl               = rtrim(get_field('event_api_url', 'option'), '/');
        $apiResourceUrl       = $apiUrl . $endPoint;
        $nonce                = md5(mt_rand());
        $oauthSignatureMethod = "HMAC-SHA1";
        $oauthTimestamp       = time();

        // Create multipart content body. Holds media to be uploaded
        $eol = "\r\n";
        define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));
        $fileContents = file_get_contents($_FILES['file']['tmp_name']);
        $content =  "--" . MULTIPART_BOUNDARY . $eol .
                    "Content-Disposition: form-data; name=\"file\"; filename=\"".rawurlencode($_FILES['file']['name'])."\"". $eol .
                    "Content-Type: " . $_FILES['file']['type']. $eol . $eol .
                    $fileContents . $eol;
        $content .= "--" . MULTIPART_BOUNDARY . "--" . $eol;

        $sigBase = "POST&" . rawurlencode($apiResourceUrl) . "&"
            . rawurlencode("oauth_consumer_key=" . rawurlencode($consumerKey)
            . "&oauth_nonce=" . rawurlencode($nonce)
            . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
            . "&oauth_timestamp=" . $oauthTimestamp
            . "&oauth_token=" . rawurlencode($accessToken)
            . "&oauth_version=" . rawurlencode($oauthVersion)
         );
        $sigKey = rawurlencode($consumerSecret) . "&" . rawurlencode($accessTokenSecret);
        $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
        $authHeader = "OAuth oauth_consumer_key=" . rawurlencode($consumerKey) . ","
            . "oauth_nonce=" . rawurlencode($nonce) . ","
            . "oauth_signature_method=" . rawurlencode($oauthSignatureMethod) . ","
            . "oauth_signature=" . rawurlencode($oauthSig) . ","
            . "oauth_timestamp=". rawurlencode($oauthTimestamp) . ","
            . "oauth_token=" . rawurlencode($accessToken) . ","
            . "oauth_version=" . rawurlencode($oauthVersion);

        $context = stream_context_create(array(
            "http" => array(
                'method' => 'POST',
                'header' => 'Content-Type: multipart/form-data; boundary=' . MULTIPART_BOUNDARY . $eol
                            . "Content-Disposition: attachment filename=\"" . rawurlencode($_FILES['file']['name']) . "\"\r\n"
                            . "Authorization: " . $authHeader . $eol,
                        'content' => $content
            ),
            'ssl' => array(
                'verify_peer' => defined('DEV_MODE') && DEV_MODE === true ? false : true,
                'verify_peer_name' => defined('DEV_MODE') && DEV_MODE === true ? false : true
            )));

        $result = file_get_contents($apiResourceUrl, false, $context);

        if ($result === false) {
            wp_send_json_error(__('Something went wrong uploading your image', 'event-integration'));
        }

        // return uploaded media id
        $resObj = json_decode($result);
        wp_send_json_success($resObj->id);
    }
Upload image to Event Manager API media end point