/
delete.php
41 lines (35 loc) · 975 Bytes
/
delete.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
<?php
// Muaz Khan - www.MuazKhan.com
// MIT License - https://www.webrtc-experiment.com/licence/
// Documentation - https://github.com/muaz-khan/RecordRTC
header("Access-Control-Allow-Origin: *");
function selfInvoker()
{
if (!isset($_POST['delete-file'])) {
echo 'PermissionDeniedError';
return;
}
$fileName = $_POST['delete-file'];
$filePath = 'uploads/' . $fileName;
// make sure that one can delete only allowed audio/video files
$allowed = array(
'webm',
'wav',
'mp4',
"mkv",
'mp3',
'ogg'
);
$extension = pathinfo($filePath, PATHINFO_EXTENSION);
if (!$extension || empty($extension) || !in_array($extension, $allowed)) {
echo 'PermissionDeniedError';
return;
}
if (!unlink($filePath)) {
echo ('Problem deleting file.');
} else {
echo ($fileName . ' deleted successfully.');
}
}
selfInvoker();
?>