-
Notifications
You must be signed in to change notification settings - Fork 3
/
video.php
executable file
·68 lines (62 loc) · 2.1 KB
/
video.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
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
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
ob_start();
$crc = filter_var($_GET['crc']);
$file = $_SESSION['defaprotect' . $crc];
if ($headerurl = @get_headers($file, 1)['Location']) {
if (!empty($headerurl)) {
$file = $headerurl;
}
}
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
$fp = @fopen($file, 'rb');
header('Content-type: video/mp4');
header("Accept-Ranges: 0-$length");
if (isset($_SERVER['HTTP_RANGE'])) {
if (isset($_SERVER['HTTP_RANGE'])) {
$c_start = $start;
$c_end = $end;
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
if (strpos($range, ',') !== false) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$end/$size");
exit;
}
if ($range == '-') {
$c_start = $size - substr($range, 1);
}else{
$range = explode('-', $range);
$c_start = $range[0];
$c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
}
$c_end = ($c_end > $end) ? $end : $c_end;
if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
header('HTTP/1.1 416 Requested Range Not Satisfiable');
header("Content-Range: bytes $start-$end/$size");
exit;
}
$start = $c_start;
$end = $c_end;
$length = $end - $start + 1;
fseek($fp, $start);
header('HTTP/1.1 206 Partial Content');
}
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: ".$length);
$opts['http']['header'] = "Range: bytes=" . ($start-$end)/$size . ",
Content-Type: video/mp4,
Accept-Ranges: bytes,
Content-Disposition: inline;,
Content-Transfer-Encoding: binary\n,".
"Connection: close";
$opts['http']['method'] = "GET";
$cong = stream_context_create($opts);
ob_end_clean();
readfile($file, false, $cong);
exit();
}