From d59e9b569fb828cdb145a3497c1b1f9e27cd03ad Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Wed, 4 Jun 2025 21:02:51 +0400 Subject: feat: verify file mime type --- lib/file.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 lib/file.php (limited to 'lib/file.php') diff --git a/lib/file.php b/lib/file.php new file mode 100644 index 0000000..4fcb607 --- /dev/null +++ b/lib/file.php @@ -0,0 +1,37 @@ +&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; +} \ No newline at end of file -- cgit v1.2.3