I've writing a php application on a LAMP server that takes a document(.odt) and populates it with the right information in the appropriate spots. While the code compiles it presents me with a print out of the header on one page and a stream of apparent gibberish on the other as follows:
''mimetypeapplication/vnd.oasis.opendocument.textPK?H?1?ᄀҡThumbnails/thumbnail.pngノPNG IHDR?g?゙ᄀルIDATxワ????ᄃrҩ?Kヨヒ\䆻ᄆ ᄊ?l?R ᄂ )?トト?jᄄ&
lcハ{??ٲz??ヨovg?6?ᄚ=yoovvv?3ᆵ?R0B#4tD~?ᄀ+ヘF 5BCL#ミᄀ!ᆭHヘ??ᄂFhネiR#4?ᄅbチ? 1ヘ@jトニリF 5BCL#ミᄀ!ᆭHヘ??ヌヤL?Dᄌă? ゙?BツD?~??HgᄂKツ PW゚ᄑロ?ᄉ?>oLR+?쟰.ᄒ?w???ᄊ8Q???タ??8&ᅠ/フ?Ć??a?8/Wᄄᆬ?,tᆬP[tᄆ캁?Is.!??.7?BN?ᄄ?0\ツ%ホ>? }?!4?テ'0?5ᄌ?xLタEᄌ?x^?4?Gᆲネ#゙??+?<4ロ?ロᄚ<???ラz??ᆬロ?Dワxk゙??Fa'フŜ -4ᄚg\ミ
6z^°??ᄂ?yᄅ
I suspect it might be an encoding issue and I've tried different approaches but so far nothing. I haven't had much luck looking for similar situations online so any suggestions/recommendations/help would be appreciated
<?php
session_start();
include 'conn.php';
if(empty($_SESSION['username']) || empty($_SESSION['password']))
print("Access to database denied");
else {
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$type = $_SESSION['type'];
if($type == "admin") {
include '../includes/aheader.html';
}
if($type == "user") {
include '../includes/uheader.html';
}
if(isset($_POST["searchButton"])) {
print_r($_POST);
$keyword = $_POST['keyword'];
$choice = $_POST['choice'];
if($choice == "company_name")
$sql = $mysqli -> prepare("SELECT * FROM clients WHERE company_name LIKE ?");
if($choice == "project_code")
$sql = $mysqli -> prepare("SELECT * FROM clients WHERE project_code LIKE ?");
$keyword = '%'.$keyword.'%';
$sql -> bind_param('s', $keyword);
$sql -> execute();
$result = $sql -> get_result();
if(!$result)
print("<p>Select query failed</p>");
else {
if($result -> num_rows == 0)
print("<p>No match found</p>");
else {
while($row = mysqli_fetch_array($result)) {
$company_name = $row['0'];
$phone = $row['1'];
$address = $row['2'];
$approximate_employees = $row['3'];
$project_code = $row['4'];
extract($row);
}
include_once('tbs_class.php');
include_once('tbs_plugin_opentbs.php');
$TBS = new clsTinyButStrong;
$TBS -> Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS -> LoadTemplate('document.odt');
$TBS -> Show(OPENTBS_FILE, 'document.odt');
$TBS -> MergeField('company_name', $company_name);
$TBS -> MergeField('address', $address);
$TBS -> MergeField('phone', $phone);
}
}
}
else {
include '../includes/searchForm.html';
include '../includes/footer.html';
}
}
$mysqli -> close();
?>
You have to merge fields before to render the result. And the result must be a file different from the template.
$TBS = new clsTinyButStrong;
$TBS -> Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
// Load the template
$TBS -> LoadTemplate('document.odt');
// Merge fields
$TBS -> MergeField('company_name', $company_name);
$TBS -> MergeField('address', $address);
$TBS -> MergeField('phone', $phone);
// Render the result
$TBS -> Show(OPENTBS_FILE, 'document_result.odt');