forked from WWBN/AVideo-Storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxsendfile.php
More file actions
68 lines (59 loc) · 2.08 KB
/
xsendfile.php
File metadata and controls
68 lines (59 loc) · 2.08 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require_once './configuration.php';
require_once './functions.php';
session_write_close();
if (empty($_GET['file'])) {
error_log("XSENDFILE GET file not found ");
die('GET file not found');
}
if(empty($_GET['token'])){
$_GET['token'] = 0;
}
$path_parts = pathinfo($_GET['file']);
$file = $path_parts['basename'];
$path = "{$global['videos_directory']}{$file}";
if ($path_parts["extension"] === "m3u8") {
$arr = explode("/", $path_parts["dirname"]);
$sfilename = end($arr);
$path = "{$global['videos_directory']}{$sfilename}/{$file}";
} else {
$sfilename = $path_parts['filename'];
}
if (!empty($_REQUEST['secret']) && $_REQUEST['secret'] === $global['secret']) {
error_log("Storage xsendfile with secret");
}else{
$url = "{$global['aVideoURL']}plugin/YPTStorage/canWatchVideo.json.php?token={$_GET['token']}&filename={$sfilename}";
$json = url_get_contents($url);
error_log("Storage xsendfile {$url} => {$json}");
if(empty($json)){
die("Streamer error: {$url}");
}
$jsonObject = json_decode($json);
if(empty($jsonObject->authorization)){
die("Not authorized: ".$json);
}
}
if (file_exists($path)) {
if (!empty($_GET['download'])) {
if(!empty($_GET['title'])){
$quoted = sprintf('"%s"', addcslashes(basename($_GET['title']), '"\\'));
}else{
$quoted = sprintf('"%s"', addcslashes(basename($_GET['file']), '"\\'));
}
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
}
header("X-Sendfile: {$path}");
if (empty($_GET['download'])) {
header("Content-type: " . mime_content_type($path));
}
header('Content-Length: ' . filesize($path));
die();
}else{
error_log("XSENDFILE ERROR: Not exists {$path} = ". json_encode($path_parts));
}