-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadpublicfile.php
38 lines (29 loc) · 991 Bytes
/
loadpublicfile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// Check if we are a user
//OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
\OC::$server->getSession()->close();
// Set the session key for the file we are about to edit.
$token = isset($_GET['token']) ? $_GET['token'] : '';
if(!empty($token))
{
header('Content-Type: application/pdf');
$linkItem = \OC::$server->getShareManager()->getShareByToken($token);
$owner = $linkItem->getShareOwner();
\OC\Files\Filesystem::tearDown();
\OC\Files\Filesystem::init($owner, '/' . $owner . '/files');
$path = '/' . \OC\Files\Filesystem::getPath($linkItem->getNodeId());
$filecontents = \OC\Files\Filesystem::file_get_contents($path);
if($filecontents)
{
echo $filecontents;
}
else
{
\OCP\Util::writeLog('files_nbviewer', 'Error while opening PDF ' . $path, \OCP\Util::ERROR);
OCP\JSON::error(['data' => ['message' => 'A problem occoured while loading the PDF']]);
}
return;
} else {
OCP\JSON::error(['data' => ['message' => 'Invalid file path supplied.']]);
}