-3

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

user727198
  • 89
  • 1
  • 2
  • 11

1 Answers1

1

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

Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Hi, thank you for your response. Is that possible to save each downloaded copy into mysql? So let me say I am using my submited code to download the file as docx and save an copy into mysql in same time. I would appreciate your input. Thank you. – user727198 Dec 02 '17 at 13:42
  • You con retrieve the binary source of the file generated by OpenTBS like any other local file : `$data = file_get_contents($output_file_name);`. Then you can insert it into the database using the end of the snipped above. You should consider to not save file binary content into the database. – Skrol29 Dec 04 '17 at 11:36