Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2168,13 +2168,22 @@ function tree_auto_load(){
echo "</body>\n</html>";
}
function is_binary($file){
//https://stackoverflow.com/questions/1765311/how-to-view-files-in-binary-from-bash
//http://php.net/manual/pt_BR/function.bin2hex.php
if (!is_file($file)) return false;
$mime = mime_content_type($file);
fb_log($file,$mime);
if (strpos($mime,'text') === false && strpos($mime,'x-empty') === false) return true;
return false;
if (!is_file($file) || !is_readable($filePath)) return false;
// If mbstring is supported, we check if the first chunk of the file has encoding (meaning it's text)
if (function_exists('mb_detect_encoding')) {
$handle = fopen($file, "rb");
if (!$handle) return false;
$chunk = fread($handle, 512);
fclose($handle);
$content = file_get_contents($file);
return mb_detect_encoding((string) $chunk, null, true) === false;
} else {
// Fallback on legacy check
$mime = mime_content_type($file);
fb_log($file,$mime);
if (strpos($mime,'text') === false && strpos($mime,'x-empty') === false) return true;
return false;
}
}
function is_textfile($file){
if (!is_file($file)) return false;
Expand Down Expand Up @@ -8676,4 +8685,4 @@ function get_base64_file(){
// +--------------------------------------------------
// | THE END
// +--------------------------------------------------
?>
?>