File size: 1,277 Bytes
dc45f00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
$response = ["code" => 400, "msg" => "failed"];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $data = json_decode(file_get_contents('php://input'), true);
    if (isset($data['filename'])) {
        $filename = basename($data['filename']); // Ensure the filename is safe

        // Define file paths
        $imagePath = 'img/' . $filename;
        $videoPath = 'videos/' . $filename;

        // Check if the file exists in the image directory
        if (file_exists($imagePath)) {
            if (unlink($imagePath)) {
                $response['code'] = 200;
                $response['msg'] = 'Image deleted successfully';
            } else {
                $response['msg'] = 'Failed to delete image';
            }
        }
        // Check if the file exists in the video directory
        elseif (file_exists($videoPath)) {
            if (unlink($videoPath)) {
                $response['code'] = 200;
                $response['msg'] = 'Video deleted successfully';
            } else {
                $response['msg'] = 'Failed to delete video';
            }
        }
        else {
            $response['msg'] = 'File not found';
        }
    } else {
        $response['msg'] = 'Filename not provided';
    }
}

echo json_encode($response);
?>