From de2d864dd371429b29d0373ad85c993bc916a469 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 13 Mar 2019 15:03:54 +0100 Subject: [PATCH] Attach `.bin` extension to attachments see #2840 --- .../lib/data/attachment/Attachment.class.php | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/wcfsetup/install/files/lib/data/attachment/Attachment.class.php b/wcfsetup/install/files/lib/data/attachment/Attachment.class.php index b7a5db3a10..49667aeaf9 100644 --- a/wcfsetup/install/files/lib/data/attachment/Attachment.class.php +++ b/wcfsetup/install/files/lib/data/attachment/Attachment.class.php @@ -123,7 +123,7 @@ class Attachment extends DatabaseObject implements IRouteController, IThumbnailF * @inheritDoc */ public function getLocation() { - return self::getStorage() . substr($this->fileHash, 0, 2) . '/' . $this->attachmentID . '-' . $this->fileHash; + return $this->getLocationHelper(self::getStorage() . substr($this->fileHash, 0, 2) . '/' . $this->attachmentID . '-' . $this->fileHash); } /** @@ -140,10 +140,33 @@ class Attachment extends DatabaseObject implements IRouteController, IThumbnailF */ public function getThumbnailLocation($size = '') { if ($size == 'tiny') { - return self::getStorage() . substr($this->fileHash, 0, 2) . '/' . $this->attachmentID . '-tiny-' . $this->fileHash; + $location = self::getStorage() . substr($this->fileHash, 0, 2) . '/' . $this->attachmentID . '-tiny-' . $this->fileHash; + } + else { + $location = self::getStorage() . substr($this->fileHash, 0, 2) . '/' . $this->attachmentID . '-thumbnail-' . $this->fileHash; + } + + return $this->getLocationHelper($location); + } + + /** + * Returns the appropriate location with or without extension. + * + * @param string $location + * @return string + */ + protected final function getLocationHelper($location) { + // Check location with extension + if (is_readable($location.'.bin')) { + return $location.'.bin'; + } + // Check legacy location + else if (is_readable($location)) { + return $location; } - return self::getStorage() . substr($this->fileHash, 0, 2) . '/' . $this->attachmentID . '-thumbnail-' . $this->fileHash; + // Assume that the attachment is not yet uploaded. + return $location.'.bin'; } /** -- 2.20.1