-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.php
85 lines (83 loc) · 1.92 KB
/
file.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
include('includes/config.php');
// File Delivery setting is pulled from config for normal music playback,
// but clicking the Download link will always override to 'download'
if ( !empty($_GET['delivery']) )
{
switch ( $_GET['delivery'] )
{
case 'download':
$delivery = 'download';
break;
case 'stream':
$delivery = 'stream';
break;
// If not one of the two actual delivery methods, then revert back to config file setting
default:
break;
}
}
$file = rawurldecode($_GET['file']);
$ext = strtolower(substr($file,-3));
$lastslash = strrpos($file,'/');
$filename = substr($file,$lastslash+1,strlen($file)-$lastslash);
// Only serve up files that exist and are in the list of supported types
if (file_exists($file) && in_array($ext, $types))
{
// Handle the supported file types
switch ($ext)
{
case 'aac':
header('Content-Type: audio/x-aac');
break;
case 'm4a':
case 'f4a':
header('Content-Type: audio/m4a');
break;
case 'mp3':
header('Content-Type: audio/mpeg');
break;
case 'ogg':
case 'oga':
header('Content-Type: audio/ogg');
break;
// If the file type isn't in the list of supported types, then kill it
default:
exit;
}
// Use appropriate file delivery method
if ( $delivery == 'download' )
{
header('Content-length: ' . filesize($file));
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($file);
}
elseif ( $delivery == 'stream' )
{
$strContext = stream_context_create(
array(
'http'=>array(
'method'=>'GET',
'header'=>'Accept-language: en\r\n'
)
)
);
header('Content-Transfer-Encoding: binary');
header('Pragma: no-cache');
header('icy-br: 128');
$fpOrigin = fopen($file, 'rb', false, $strContext);
while ( !feof($fpOrigin))
{
$buffer = fread($fpOrigin,4096);
echo $buffer;
flush();
}
fclose($fpOrigin);
}
else
{
// Don't do anything if unexpected delivery method
exit;
}
}
?>