diff options
author | Chris Smith <toonarmy@phpbb.com> | 2009-06-03 10:19:17 +0000 |
---|---|---|
committer | Chris Smith <toonarmy@phpbb.com> | 2009-06-03 10:19:17 +0000 |
commit | be8457d3c418441317177bfcdf7378410ac28d55 (patch) | |
tree | 49311dfed0e35e06d194ffe15cba7e5941b339e8 /phpBB/includes/functions.php | |
parent | 62aa26c9a6681956bfb8af61447cd078271cc0a0 (diff) | |
download | forums-be8457d3c418441317177bfcdf7378410ac28d55.tar forums-be8457d3c418441317177bfcdf7378410ac28d55.tar.gz forums-be8457d3c418441317177bfcdf7378410ac28d55.tar.bz2 forums-be8457d3c418441317177bfcdf7378410ac28d55.tar.xz forums-be8457d3c418441317177bfcdf7378410ac28d55.zip |
Correctly determine writable status of files on Windows operating system. #39035
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9528 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r-- | phpBB/includes/functions.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 58601be65b..78905beff6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -669,6 +669,67 @@ function phpbb_chmod($filename, $perms = CHMOD_READ) return $result; } +/** + * Test if a file/directory is writable + * + * This function calls the native is_writable() when not running under + * Windows and it is not disabled. + * + * @param string $file Path to perform write test on + * @return bool True when the path is writable, otherwise false. + */ +function phpbb_is_writable($file) +{ + if (substr(PHP_OS, 0, 3) === 'WIN' || !function_exists('is_writable')) + { + if (file_exists($file)) + { + // Canonicalise path to absolute path + $file = phpbb_realpath($file); + + if (is_dir($file)) + { + // Test directory by creating a file inside the directory + $result = @tempnam($file, 'i_w'); + + if (is_string($result) && file_exists($result)) + { + unlink($result); + + // Ensure the file is actually in the directory (returned realpathed) + return (strpos($result, $file) === 0) ? true : false; + } + } + else + { + $handle = @fopen($file, 'r+'); + + if (is_resource($handle)) + { + fclose($handle); + return true; + } + } + } + else + { + // file does not exist test if we can write to the directory + + $dir = dirname($file); + + if (file_exists($dir) && is_dir($dir) && phpbb_is_writable($dir)) + { + return true; + } + } + return false; + } + else + { + return is_writable($file); + } +} + // Compatibility functions if (!function_exists('array_combine')) |