aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin <robin@Amaya.(none)>2010-04-25 18:27:02 +0200
committerRobin <robin@Amaya.(none)>2010-04-25 18:27:02 +0200
commit854e0c5a9c9060e827fbbfddffeeeadfc2d27278 (patch)
tree06e38c6a96768e1721578b0a75e72488e55c5c8f
parenteaf0024c0f56b33754217d6ddb95ba021deefccf (diff)
downloadnextcloud-server-854e0c5a9c9060e827fbbfddffeeeadfc2d27278.tar.gz
nextcloud-server-854e0c5a9c9060e827fbbfddffeeeadfc2d27278.zip
bug fix in mimetype detect code
-rwxr-xr-xinc/lib_files.php45
1 files changed, 44 insertions, 1 deletions
diff --git a/inc/lib_files.php b/inc/lib_files.php
index 6188723c028..2e77067b4a7 100755
--- a/inc/lib_files.php
+++ b/inc/lib_files.php
@@ -205,7 +205,7 @@ class OC_FILES {
} else if (function_exists("mime_content_type")) {
// use mime magic extension if available
$mime_type = mime_content_type($fspath);
- } else if ($this->_can_execute("file")) {
+ } else if (OC_FILES::canExecute("file")) {
// it looks like we have a 'file' command,
// lets see it it does have mime support
$fp = popen("file -i '$fspath' 2>/dev/null", "r");
@@ -255,6 +255,49 @@ class OC_FILES {
return $mime_type;
}
+
+ /**
+ * detect if a given program is found in the search PATH
+ *
+ * helper function used by _mimetype() to detect if the
+ * external 'file' utility is available
+ *
+ * @param string program name
+ * @param string optional search path, defaults to $PATH
+ * @return bool true if executable program found in path
+ */
+ function canExecute($name, $path = false)
+ {
+ // path defaults to PATH from environment if not set
+ if ($path === false) {
+ $path = getenv("PATH");
+ }
+
+ // check method depends on operating system
+ if (!strncmp(PHP_OS, "WIN", 3)) {
+ // on Windows an appropriate COM or EXE file needs to exist
+ $exts = array(".exe", ".com");
+ $check_fn = "file_exists";
+ } else {
+ // anywhere else we look for an executable file of that name
+ $exts = array("");
+ $check_fn = "is_executable";
+ }
+
+ // now check the directories in the path for the program
+ foreach (explode(PATH_SEPARATOR, $path) as $dir) {
+ // skip invalid path entries
+ if (!file_exists($dir)) continue;
+ if (!is_dir($dir)) continue;
+
+ // and now look for the file
+ foreach ($exts as $ext) {
+ if ($check_fn("$dir/$name".$ext)) return true;
+ }
+ }
+
+ return false;
+ }
}