Send Exported Report to the Server

This example shows how to send and save an exported report on the PHP server side using the HTML Viewer. For this, you need to add the onEndExportReport event handler. Also, if you want to save the exported report only on the server side, you need to prevent the built-in file handling. To do this, simply set the event.preventDefault property to true.

viewer.onEndExportReport = function (event) {
event.preventDefault = true;
<?php StiHelper::createHandler(); ?>

On the PHP server side, you can get the Base64 data stream of the exported report. This can be done in the $handler->onEndExportReport event in the handler.php file. Further, for example, you can save it to a file in the 'reports' folder.

$handler->onEndExportReport = function ($event) {
$format = $event->format; // Export format
$data = $event->data; // Base64 export data
$fileName = $event->fileName; // Report file name

file_put_contents('reports/'.$fileName.'.'.strtolower($format), base64_decode($data));

//return StiResult::success();
return StiResult::success("Export OK. Message from server side.");
//return StiResult::error("Export ERROR. Message from server side.");