From 2255d593ba5cdb775c1d4ce79e63ca1d5c98a5e1 Mon Sep 17 00:00:00 2001 From: thaaoblues Date: Tue, 1 Oct 2024 20:55:14 +0200 Subject: [PATCH] better brut text file recognition --- utils/inputs.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/utils/inputs.php b/utils/inputs.php index 5aa7db5..ebd6e3e 100644 --- a/utils/inputs.php +++ b/utils/inputs.php @@ -100,8 +100,36 @@ function checkFileTypeSecure($filePath) { } } + + // brut text file that don't have BOM (magic byte) + if(is_utf8($filePath)){ + return 1; + } + return 0; // Unknown or unsupported file type } +function is_utf8_file($filePath) { + // Check if the file exists + if (!file_exists($filePath)) { + return false; + } + + // Open the file for reading + $fileContents = file_get_contents($filePath); + if ($fileContents === false) { + return false; // Unable to read the file + } + + // Check if the file content is valid UTF-8 + return is_utf8($fileContents); +} + +// Helper function to check if a string is valid UTF-8 +function is_utf8($string) { + return mb_check_encoding($string, 'UTF-8'); +} + + ?> \ No newline at end of file