Tim Aldridge
Member
We discovered an interesting bug when trying to upload low KB files on cloud servers. Anything smaller than 32kb would throw a rename error. Apparently on a cloud server, the rename throws an exception faster than the cloud to check if the file already exists. In Avatar.php, we added this small try/catch and now any size avatar will work.
PHP:
protected function _writeAvatar($userId, $size, $tempFile)
{
if (!in_array($size, array_keys(self::$_sizes)))
{
throw new XenForo_Exception('Invalid avatar size.');
}
$filePath = $this->getAvatarFilePath($userId, $size);
$directory = dirname($filePath);
if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory))
{
if (file_exists($filePath))
{
unlink($filePath);
}
try {
$success = rename($tempFile, $filePath);
} catch (Exception $e) {
$success = file_exists($filePath);
}
if ($success)
{
XenForo_Helper_File::makeWritableByFtpUser($filePath);
}
return $success;
}
else
{
return false;
}
}