From b84fdbf0085a1ef117ad58d02ec9b61586a20b7e Mon Sep 17 00:00:00 2001 From: Whale Date: Fri, 27 Dec 2019 14:09:52 +0800 Subject: [PATCH] Compatible with macOS (#258) --- tinyfilemanager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index cc3417a..f1becd3 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -2200,8 +2200,12 @@ function fm_get_translations($tr) { function fm_get_size($file) { static $iswin; + static $isdarwin; if (!isset($iswin)) { $iswin = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'); + } + if (!isset($isdarwin)) { + $isdarwin = (strtoupper(substr(PHP_OS, 0)) == "DARWIN"); } static $exec_works; @@ -2211,7 +2215,7 @@ function fm_get_size($file) // try a shell command if ($exec_works) { - $cmd = ($iswin) ? "for %F in (\"$file\") do @echo %~zF" : "stat -c%s \"$file\""; + $cmd = ($iswin) ? "for %F in (\"$file\") do @echo %~zF" : ($isdarwin ? "stat -f%z \"$file\"" : "stat -c%s \"$file\""); @exec($cmd, $output); if (is_array($output) && ctype_digit($size = trim(implode("\n", $output)))) { return $size;