blob: 4fcb60797cfb80ca91c2fa0b1f3be0bb3ce2cea4 (
plain)
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
|
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
function verify_mimetype(string $file_path, string $mimetype): bool
{
$path = escapeshellarg($file_path);
if (str_starts_with($mimetype, 'image/')) {
$output = shell_exec("identify -quiet -ping $path");
return !empty($output);
} else if (str_starts_with($mimetype, 'video/') || str_starts_with($mimetype, 'audio/')) {
$output = [];
$exitCode = 0;
$cmd = 'ffprobe -v error -i "/path/to/video.mp4" 2>&1';
exec($cmd, $output, $exitCode);
return $exitCode === 0;
}
throw new RuntimeException("Illegal type for MIME verifications: $mimetype");
}
function delete_file(string $file_id, string $file_extension): bool
{
$paths = [
FILE_UPLOAD_DIRECTORY . "/{$file_id}.{$file_extension}",
FILE_THUMBNAIL_DIRECTORY . "/{$file_id}.webp",
FILE_METADATA_DIRECTORY . "/{$file_id}.metadata.json"
];
foreach ($paths as $path) {
if (is_file($path) && !unlink($path)) {
return false;
}
}
return true;
}
|