// combine.php require "../php/functions.php"; echo "COMBINE.PHP\n"; $THIS_ABSOLUTE_FILE_NAME = $_SERVER["SCRIPT_FILENAME"]; $THIS_FILE_NAME = preg_replace("/.*\\//", "", $THIS_ABSOLUTE_FILE_NAME); // get input $IMAGE_DATA_KEY = "imageData"; $FILE_NAME_KEY = "fileName"; // IMAGE DATA $imageDataValue = parameterFromGETorPOST($IMAGE_DATA_KEY, null); // FILE NAME $imageDataFileNameValue = parameterFromGETorPOST($FILE_NAME_KEY, null); // if (false) { //$imageDataValue){ // output to file $binaryDataValue = base64ToBinary($imageDataValue, null); $fileOutName = "./temp/binary.png"; touch($fileOutName); if (file_exists($fileOutName)) { chmod($fileOutName, 0775); $fileHandle = fopen($fileOutName, "w"); if ($fileHandle) { fwrite($fileHandle, $binaryDataValue); fclose($fileHandle); echo "saved"; } } } else { if (false) { // create canvas $canvasWidth = 1024;
} if (!$filename) { $filename = "out.png"; } // error_log("filename:".$filename.""); // error_log("command:".$command.""); // error_log("data:".$data.""); // phpinfo(); //echo "MAC: ".IS_SERVER_OSX(); //return; if ($command == $COMMAND_UPLOAD) { if (!$data) { echo "no data"; return; } $binaryFile = base64ToBinary($data); $outputFilename = "./temp/" . $filename; //$saved = file_put_contents($outputFilename, $binaryFile); $fileHandle = fopen($outputFilename, "w"); $saved = fwrite($fileHandle, $binaryFile); fclose($fileHandle); echo "saved: " . $saved; return; } if ($command == $COMMAND_COMBINE) { if (!$data) { echo "no data"; return; } $json = json_decode($data); $fileDirectoryPrefix = "./temp/";
if ($doc === false) { die('No Document Found, Please contact Support Desk. Thank You!'); } $doc = (object) $doc; $doc->name = isset($doc->document_name) && $doc->document_name != '' ? $doc->document_name : 'temp.pdf'; $doc->is_temp = 'true'; $document = base64ToBinary($doc->document); } else { $d = MatchaModel::setSenchaModel('App.model.patient.PatientDocuments'); $doc = $d->load($_REQUEST['id'])->one(); if ($doc === false) { die('No Document Found, Please contact Support Desk. Thank You!'); } $doc = (object) $doc; $doc->is_temp = 'false'; $document = base64ToBinary($doc->document, $doc->encrypted); } $mineType = get_mime_type($doc->name); if (preg_match('/^image/', $mineType)) { $document = base64_encode($document); $html = <<<HTML <!doctype html> <html> \t<head> \t \t<meta charset="UTF-8"> \t \t<link rel="stylesheet" href="../lib/darkroomjs/build/css/darkroom.min.css"> \t</head> \t<body> \t<div class="image-container target"> \t \t<img src="data:{$mineType};base64,{$document}" style="width:100%;" alt="" id="target" crossOrigin="anonymous"> </div>
} else { $doc->document = base64_decode($doc->document); } return $doc; } if (isset($_REQUEST['temp'])) { $d = MatchaModel::setSenchaModel('App.model.patient.PatientDocumentsTemp'); $doc = $d->load($_REQUEST['id'])->one(); if ($doc === false) { die('No Document Found, Please contact Support Desk. Thank You!'); } $doc = (object) $doc; $doc->name = 'temp.pdf'; $doc = base64ToBinary($doc); } else { $d = MatchaModel::setSenchaModel('App.model.patient.PatientDocuments'); $doc = $d->load($_REQUEST['id'])->one(); if ($doc === false) { die('No Document Found, Please contact Support Desk. Thank You!'); } $doc = base64ToBinary($doc); } header('Content-Type: ' . get_mime_type($doc->name)); header('Content-Disposition: inline; filename="' . $doc->name . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . strlen($doc->document)); header('Accept-Ranges: bytes'); print $doc->document; } else { print 'Not Authorized to be here, Please contact Support Desk. Thank You!'; }