/** * Ensures that the specified file can be written to by the FTP user. * This generally doesn't need to do anything if PHP is running via * some form of suexec. It's primarily needed when running as apache. * * @param string $file * @return boolean */ public static function makeWritableByFtpUser($file) { if (self::$_chmodDirectory === null) { if (XenForo_Application::isRegistered('config')) { $chmod = XenForo_Application::get('config')->chmodWritableValue; if ($chmod) { self::$_chmodDirectory = XenForo_Application::get('config')->chmodWritableValue | 0111; self::$_chmodFile = XenForo_Application::get('config')->chmodWritableValue; } } if (!self::$_chmodFile) { $selfWritable = null; if (PHP_SAPI == 'cli') { $uid = false; if (function_exists('posix_getuid')) { $uid = @posix_getuid(); } else { $tempFile = tempnam(self::getTempDir(), 'xf'); if ($tempFile) { $uid = fileowner($tempFile); @unlink($tempFile); } } if ($uid !== false) { $lock = self::getInternalDataPath() . '/install-lock.php'; if (file_exists($lock)) { // if we're running as who created the lock file, // then the web access is likely running with the same user $selfWritable = $uid == fileowner($lock); } else { if ($uid == 0) { // if we're root, just force w+w $selfWritable = false; } } } } if ($selfWritable === null) { $selfWritable = @is_writable(__FILE__); } if ($selfWritable) { // writable - probably owned by ftp user already self::$_chmodDirectory = 0755; self::$_chmodFile = 0644; } else { // not writable, so file is probably owned by "nobody", need to w+w it self::$_chmodDirectory = 0777; self::$_chmodFile = 0666; } } } if (@is_readable($file)) { return @chmod($file, @is_file($file) ? self::$_chmodFile : self::$_chmodDirectory); } else { return false; } }