我希望能够从我的网站打开我电脑上存在的 Office 文档(从长远来看,它们将是存储在我们网络的 NAS 服务器上的文件)
所以我通过这个命令在我的电脑上安装了OnlyOffice(我在 Windows 10 上)
docker run -i -t -d -p 90:80 --restart=always onlyoffice/documentserver
我使用了 90 端口,因为 Wamp 已经使用了 80 端口
然后在我本地托管的网站上,感谢 Wamp,我创建了这个文件:
索引.html
<div id="placeholder" style="height: 100%"></div>
<script type="text/javascript" src="http://localhost:90/web-apps/apps/api/documents/api.js"></script>
<script type="text/javascript">
window.docEditor = new DocsAPI.DocEditor("placeholder",
{
"document": {
"fileType": "docx",
"title": "Example Document Title.docx",
"url": "https://file-examples-com.github.io/uploads/2017/02/file-sample_500kB.docx"
},
"documentType": "word",
"editorConfig": {
"mode": "view"
},
"height": "100%",
"width": "100%"
});
</script>
(使用它工作的外部网站的网址)
所以我修改了我的脚本以这种方式检索本地托管的文件
注意:http://mysite.test
是对应于http://localhost/mysite
(在 WAMP 上)的虚拟主机
Index.html(版本 2)
<script type="text/javascript" src="http://localhost:90/web-apps/apps/api/documents/api.js"></script>
<script type="text/javascript">
window.docEditor = new DocsAPI.DocEditor("placeholder",
{
"document": {
"fileType": "docx",
"title": "Example Document Title.docx",
"url": "http://mysite.test/get_file.php"
},
"documentType": "word",
"editorConfig": {
"mode": "view"
},
"height": "100%",
"width": "100%"
});
</script>
获取文件.php
<?php
$file_url = 'C:\Users\user\Desktop\test.docx';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=test.docx");
readfile($file_url);
?>
在那里它不起作用!(如果我直接从链接访问,则文件已正确下载http://mysite.test/get_file.php
)
我在 index.html 上有这个错误:
Download failed.
码头工人日志:
[2021-01-06T14:04:18.136] [ERROR] nodeJS - error downloadFile:url=http://mysite.test/get_file.php;attempt=3;code:null;connect:null;(id=127d6893c0ab2f9f8b71)
Error: Error response: statusCode:404 ;body:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /get_file.php</pre>
</body>
</html>
at Request._callback (/snapshot/server/build/server/Common/sources/utils.js:0:0)
at Request.init.self.callback (/snapshot/server/build/server/Common/node_modules/request/request.js:185:22)
at Request.emit (events.js:198:13)
at Request.<anonymous> (/snapshot/server/build/server/Common/node_modules/request/request.js:1154:10)
at Request.emit (events.js:198:13)
at Gunzip.<anonymous> (/snapshot/server/build/server/Common/node_modules/request/request.js:1076:12)
at Object.onceWrapper (events.js:286:20)
at Gunzip.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1143:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
我使用了一个 get_file.php PHP 文件,因为最终它将管理网站上已经存在的用户的权限(例如 user1 只能访问 .docx 文件,而 user2 只能访问 .xlsx 文件)
你能告诉我如何使用 OnlyOffice 查看我的本地文件(NAS 服务器上的未来)吗?