Categories > OpenTBS with ODT >

Problem getting a Mergeblock to work with a PHP array I get a corrupted file

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Allen
Date: 2012-05-08
Time: 19:27

Problem getting a Mergeblock to work with a PHP array I get a corrupted file

Hello, I am new to TBS and Open TBS, but I see it's potential.

I've written a code which takes lines from a text doc and puts them in a php array.  I am then trying to put the array then through a Mergeblock.

Here is the code after I get the connection to MySQL:


     include_once('..\tbs_class.php');
     include_once('..\tbs_plugin_opentbs.php');
   
    $line = array();
   
    $docid = $_POST["Motion"];

    $result = mysql_query("SELECT * FROM `motionlist` WHERE `ID` = " . $docid) or die(mysql_error()); // gets the URL of the Motion to use

    $row = mysql_fetch_array($result);

    $file = fopen($row['Template'], 'r') or die("Can't open file");  // opens the text doc
   
    $i = 1;

    while(!feof($file)) //Inserts the text doc line by line into the php array
      {
          $line[$i] = array('textdoc'=>fgets($file));
        $i= $i + 1;
    }

    fclose($file);

    $TBS = new clsTinyButStrong;

    $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

    $TBS->LoadTemplate('motiontest.odt');

    $TBS->MergeBlock('block1', $line);        // merge block

    $file_name = "thetest.odt";
   
    $TBS->Show(OPENTBS_DOWNLOAD, $file_name);
?>


The template block at the moment is


[block1.textdoc]


but I have tried a lot of other versions of this as well.

The document does download but when I open the file up I get 26 pages of compress materials that start like this.


PK}ˆ¨@^Æ2


I thought at first it was my array, then I thought it might be my merge block, and then I thought it was the show method.

I don't know what to think now. 

Any thoughts on how to get this to work will be deeply appreciated, even if it is a reference that will give me a clue.

Allen



By: Skrol29
Date: 2012-05-08
Time: 23:56

Re: Problem getting a Mergeblock to work with a PHP array I get a corrupted file

Hi Allen,

This type of error typically happens when your PHP code output some text  before you you call the Show() method.
It produce a corrupted file.

I suggest that you try the debug mode: http://www.tinybutstrong.com/plugins/opentbs/tbs_plugin_opentbs.html#debug
By: Allen
Date: 2012-05-09
Time: 04:33

Re: Problem getting a Mergeblock to work with a PHP array I get a corrupted file

Thank you.  It worked perfectly.