From acc609a74d5f1bb697d645c7a122bbda5914f06f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 17 Aug 2014 22:33:37 -0700 Subject: [PATCH] CRM-15126, CRM-14949 - CRM_Utils_File - Fix dynamicResourcePath() and absoluteDirectory() - In dynamicResourcePath(), don't allow mixed-delimiters to produce double-delimiters (e.g. "files/civicrm/\dynamic") - Update absoluteDirectory() to work in Windows --- CRM/Utils/File.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/File.php b/CRM/Utils/File.php index b24eb271ca..82a18ccc0c 100644 --- a/CRM/Utils/File.php +++ b/CRM/Utils/File.php @@ -527,8 +527,9 @@ HTACCESS; * @return string */ static function absoluteDirectory($directory) { - // Do nothing on windows - config will need to specify absolute path - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + // check if directory is already absolute, if so return immediately + // Note: Windows PHP accepts any mix of "/" or "\", so "C:\htdocs" or "C:/htdocs" would be a valid absolute path + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && preg_match(';^[a-zA-Z]:[/\\\\];', $directory)) { return $directory; } @@ -713,7 +714,9 @@ HTACCESS; static function dynamicResourcePath($fileName = NULL) { $config = CRM_Core_Config::singleton(); // FIXME: Use self::baseFilePath once url issue has been resolved - $path = self::addTrailingSlash(str_replace(array('/persist/contribute', '\persist\contribute'), '', $config->imageUploadDir)) . 'dynamic'; + // Windows PHP accepts any mix of "/" or "\"; simpler if we only deal with one of those + $imageUploadDir = str_replace('\\', '/', $config->imageUploadDir); + $path = self::addTrailingSlash(str_replace('/persist/contribute', '', $imageUploadDir)) . 'dynamic'; if ($fileName !== NULL) { $path .= "/$fileName"; } -- 2.25.1