ONLYOFFICE是一個(gè)開(kāi)源的協(xié)作套件,可以將其集成到PHP應(yīng)用程序中,以便在線編輯和共享文檔
安裝ONLYOFFICE Document Server:首先,您需要在服務(wù)器上安裝ONLYOFFICE Document Server。您可以從官方網(wǎng)站下載Docker鏡像并運(yùn)行容器。
創(chuàng)建ONLYOFFICE API密鑰:為了保護(hù)API調(diào)用,您需要生成一個(gè)密鑰。這將在ONLYOFFICE Document Server和您的PHP應(yīng)用程序之間建立安全連接。
安裝ONLYOFFICE PHP SDK:在您的PHP項(xiàng)目中,使用Composer安裝ONLYOFFICE PHP SDK。這將使您能夠更輕松地與ONLYOFFICE Document Server進(jìn)行交互。
composer require onlyoffice/documentserver-php-sdk
require_once __DIR__ . '/vendor/autoload.php';
use OnlyOffice\SDK\OnlyOffice;
$onlyOffice = new OnlyOffice([
'documentServerUrl' => 'https://your-document-server.com',
'apiSecretKey' => 'your-secret-key'
]);
$editor = $onlyOffice->createEditor([
'documentId' => 'your-document-id',
'documentUrl' => 'https://your-document-url.com',
'callbackUrl' => 'https://your-callback-url.com'
]);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ONLYOFFICE Integration</title>
</head>
<body>
<?php echo $editor->getHtml(); ?>
</body>
</html>
// callback.php
require_once __DIR__ . '/vendor/autoload.php';
use OnlyOffice\SDK\OnlyOffice;
$onlyOffice = new OnlyOffice([
'documentServerUrl' => 'https://your-document-server.com',
'apiSecretKey' => 'your-secret-key'
]);
$callback = $onlyOffice->handleCallback($_POST);
if ($callback->isValid()) {
// Process the updated document, e.g., save it to your database or storage system
} else {
// Handle invalid callback requests
}
現(xiàn)在,您已經(jīng)成功地將ONLYOFFICE集成到了您的PHP應(yīng)用程序中。用戶(hù)可以在線編輯文檔,并在編輯完成后接收更新通知。