문제

I have a database table to store my templates(.docx file). I am using openTbs to work on that templates.My need is that to take out the template and store it in thee server itself, and edit using openTbs.

My question is that how I can retrieve .docx file from database and store that in the server side.? (The storing may be temporary but i want to edit it using openTbs.)

Thanks in advance.......

도움이 되었습니까?

해결책

It is bad practice to save binary data in the database, mostly when this data are intend to be processed by a file server, such as pictures or your DOCX.

Anyway, since OpenTBS 1.8.1, you can open an DOCX (or any Ms Office, LibreOffie or zip archive) from a PHP file handle.

You can use this feature to easily merge your template from the database :

// retrieve binary data of the file
$rs = mysql_query($dbc, "SELECT data FROM files WHERE id=$id");
$rec= mysql_fetch_array($rs, MYSQLI_ASSOC);
mysql_free($rs);

// create a temporary file
$temp = tmpfile();
fwrite($temp, $rec['file']);
unset($rec); // free PHP memory

// Open the file with OpenTBS
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate($temp);
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top