OpenTBS / php输出问题

时间:2016-02-18 17:51:23

标签: php opentbs

我在LAMP服务器上编写了一个php应用程序,它接收一个文档(.odt)并在适当的位置用正确的信息填充它。当代码编译时,它会向我显示一页上的标题打印和另一页明显的乱码流,如下所示:

''mimetypeapplication / vnd.oasis.opendocument.textPK?H?1?ㄱㄱThumbnails/ thumbnail.pngノPNG IHDR?g?゙ㄱルIDATxワ???﾿?ᄃrҩ?Kヨヒ\䆻ᄆ ᄊ?l?R ᄂ )?トト?jᄄ& lcハ{??ٲz??ヨlug?6?ㅀ= yoovvv?3ㄿ?R0B#4tD~?ㄱ+ヘF 5BCL#ミㄱ!ㄶHヘ??ㄴh##4?ㄹbチ? 1ヘ@jトニリF 5BCL#ミㄱ!ㄶHヘ??ヌヤL?Dㅈă?゙?BツD?〜?? HgㄴKツPW゚ㅍロ?ㅅ?&gt; oLR +?ㅎ。ㅎ?w ???ㅆ8Q???タ?? 8&amp;ㅤ/フ?Ć?? a ?8 / Wㄸㄵ?,叔ㄵP [吨ㅁ캁?是!?? 7?BN?ㄸ?0 \ツ%ホ&GT ;? }?4?テ'0?5ㅈ?xLタ؀Eㅈ?x ^?4?Gㄼネ#゙?? + ?<4ロ?ロᄚ<???ラz??ᆬロ?Dワxk゙??Fa'フŜ -4ᄚg\ミ 6z ^°??ㄴ?yㄹ

我怀疑它可能是一个编码问题,我尝试了不同的方法,但到目前为止还没有。我没有太多运气在网上寻找类似的情况,所以任何建议/建议/帮助将不胜感激

<?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();

&GT;

1 个答案:

答案 0 :(得分:0)

您必须先合并字段才能呈现结果。 结果必须是与模板不同的文件。

        $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');