-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadfile.php
44 lines (37 loc) · 1.27 KB
/
loadfile.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
39
40
41
42
43
44
<?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.
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$filename = isset($_GET['file']) ? $_GET['file'] : '';
$token = isset($_GET['token']) ? $_GET['token'] : '';
if(!empty($filename))
{
header('Content-Type: application/pdf');
if(!empty($token))
{
$linkItem = \OC::$server->getShareManager()->getShareByToken($token);
$owner = $linkItem->getShareOwner();
\OC\Files\Filesystem::init($owner, '/' . $owner . '/files');
$dir = '/' . \OC\Files\Filesystem::getPath($linkItem->getNodeId());
$dir = rtrim($dir, '/');
}
$path = $dir.'/'.$filename;
$filecontents = \OC\Files\Filesystem::file_get_contents($path);
if($filecontents)
{
echo $filecontents;
}
else
{
\OCP\Util::writeLog('files_pdfviewer', 'Error when 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.']]);
}