如何解决OnlyOffice - 从网站访问本地文件
我希望能够从我的网站打开我 PC 上的 Office 文档(从长远来看,它们将是存储在我们网络的 NAS 服务器上的文件)
所以我通过这个命令在我的 PC 上安装了 OnlyOffice(我使用的是 Windows 10)
docker run -i -t -d -p 90:80 --restart=always onlyoffice/documentserver
我使用了 90 端口,因为 80 端口已经被 Wamp 使用了
然后在我本地托管的网站上,由于 Wamp 我创建了这个文件:
Index.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","url": "http://mysite.test/get_file.PHP"
},"width": "100%"
});
</script>
get_file.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.
Docker 日志:
[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 服务器上)?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。