File: /var/www/html/wp-content/themes/ormedia/qrpatrol/qrpatrol-mme.php
<?php
require_once('../../../../wp-load.php');
// get username and password
$u = $wpdb->get_row("SELECT * from keylab_qrpatrol where ID=1");
//API Url
$url = 'https://ws.followmystaff.com/api/v3/getToken';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'username' => $u->un,
'password' => $u->up
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Execute the request
$result = curl_exec($ch);
$resultArray = json_decode($result);
$apiToken = $resultArray->apiToken;
require_once 'formr/class.formr.php';
require "libs/HTML_Object.php";
$form = new Formr();
$tid = $form->get('tid');
#header("Content-Encoding: UTF-8");
header('content-type: image/png');
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="MME_'.$tid.'.png"');
$url = "https://ws.followmystaff.com/api/v3/transactions/$tid/image";
$ch = curl_init($url);
#curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array ('x-access-token:'.$apiToken) );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
#echo '<img src="data:image/jpeg;base64,'.base64_decode($result).'"/>';
#echo base64_decode($result);
#echo base64_encode($image);
echo '<img src="data:image/png;base64,' . base64_encode($result) . '">';
#$objHTMLDocument->body()
# ->content($body);
#$objHTMLDocument->display();
?>