From c734db91064944637e361f90ed90b30d48a7d910 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 24 Jun 2025 22:35:29 +0500 Subject: feat: flash (.swf) support --- lib/file.php | 8 ++++++-- lib/thumbnails.php | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/file.php b/lib/file.php index fc3e38a..61c4fb8 100644 --- a/lib/file.php +++ b/lib/file.php @@ -4,16 +4,20 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php'; function verify_mimetype(string $file_path, string $mimetype): bool { $path = escapeshellarg($file_path); + $output = []; + $exitCode = 0; 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 2>&1"; exec($cmd, $output, $exitCode); return $exitCode === 0; + } else if ($mimetype == 'application/x-shockwave-flash') { + $cmd = "swfdump $path 2>&1"; + exec($cmd, $output, $exitCode); + return $exitCode === 0; } throw new RuntimeException("Illegal type for MIME verifications: $mimetype"); diff --git a/lib/thumbnails.php b/lib/thumbnails.php index 5afc775..5e99087 100644 --- a/lib/thumbnails.php +++ b/lib/thumbnails.php @@ -10,7 +10,15 @@ function generate_image_thumbnail(string $src_path, string $dst_path, int $width $result_code = null; - exec(command: "magick $input_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code); + if (str_ends_with($src_path, ".swf")) { + exec(command: "swfrender $input_path -o $output_path", result_code: $result_code); + if ($result_code != 0) { + return $result_code; + } + exec(command: "magick $output_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code); + } else { + exec(command: "magick $input_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code); + } return $result_code; } -- cgit v1.2.3