From: Tim Düsterhus Date: Wed, 13 Mar 2019 14:03:54 +0000 (+0100) Subject: Attach `.bin` extension to attachments X-Git-Tag: 5.2.0_Alpha_1~219^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=de2d864dd371429b29d0373ad85c993bc916a469;p=GitHub%2FWoltLab%2FWCF.git Attach `.bin` extension to attachments see #2840 --- 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'; } /**