-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice.php
More file actions
51 lines (48 loc) · 1.46 KB
/
slice.php
File metadata and controls
51 lines (48 loc) · 1.46 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
<?php
function sliceSound()
{
$path = getcwd();
if ($_GET) {
//TODO: security!
$filename = generateRandomString(6);
$cmd = "ffmpeg -ss " .
$_GET['start'] .
" -i \"{$path}/music/{$_GET['sound']}\"" .
" -t {$_GET['stop']}" .
" \"" . $path . '/sample/' . $filename . ".wav\"";
// echo "DBG";
system($cmd);
// echo "TEST";
downloadSound($filename);
} else {
echo "Brak parametrow";
}
}
function downloadSound($file){
$path = getcwd() . '/sample/' . $file . ".wav";
echo $path;
if (file_exists($path)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
ob_clean();
flush();
readfile($path);
exit;
}
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
sliceSound();