diff --git a/lib/files/view.php b/lib/files/view.php
index dfcb770328bd4dd6161708ee64d47b00095bec53..1a234228eab34c4370effa6d98fe8c63baea0291 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -509,11 +509,7 @@ class View {
 		if (Filesystem::isValidPath($path)) {
 			$source = $this->fopen($path, 'r');
 			if ($source) {
-				$extension = '';
-				$extOffset = strpos($path, '.');
-				if ($extOffset !== false) {
-					$extension = substr($path, strrpos($path, '.'));
-				}
+				$extension = pathinfo($path, PATHINFO_EXTENSION);
 				$tmpFile = \OC_Helper::tmpFile($extension);
 				file_put_contents($tmpFile, $source);
 				return $tmpFile;