Search code examples
mysqldocxtinybutstrong

Save docx into mysql


I am using the tinybutstrong to generate docx files from a template. Currently the generated document will be downloaded as file. The following code is in use:

...
$output_file_name = date('Y_m_d').'CR_Id='.$Id.'.docx';
$TBS->Show(OPENTBS_DOWNLOAD, $output_file_name);
exit(); 

But I want to have the generated docx saved directly into mysql as file. I have a table in mysql to upload files.

Is that possible? If yes, then how should the abouve document look like?

thanks


Solution

  • It's generally a bad practice to store binary files in a database.

    Nevertheless, it is possible to retrieve the binary result of the OpenTBS directly in PHP instead of save it into a file.

    Example:

    $TBS->Show(OPENTBS_STRING);
    $data = mysql_real_escape_string($TBS->Source); 
    $sql = "INSERT INTO my_table (bin_data) VALUES ('$data')";
    $result = mysql_query($sql);
    

    See the documentation for more info