X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c1f67372a70c45be7558feb8ef2143d63584dbd8..refs/pull/2734/head:/app/Uploads/ImageService.php diff --git a/app/Uploads/ImageService.php b/app/Uploads/ImageService.php index ee42e6e33..7793aaa01 100644 --- a/app/Uploads/ImageService.php +++ b/app/Uploads/ImageService.php @@ -60,7 +60,7 @@ class ImageService int $resizeHeight = null, bool $keepRatio = true ) { - $imageName = $this->sanitizeFileName($uploadedFile->getClientOriginalName()); + $imageName = $uploadedFile->getClientOriginalName(); $imageData = file_get_contents($uploadedFile->getRealPath()); if ($resizeWidth !== null || $resizeHeight !== null) { @@ -106,9 +106,9 @@ class ImageService } try { - $storage->put($fullPath, $imageData); - $storage->setVisibility($fullPath, 'public'); + $storage->put($fullPath, $imageData, ['visibility' => 'public']); } catch (Exception $e) { + \Log::error('Error when attempting image upload:' . $e->getMessage()); throw new ImageUploadException(trans('errors.path_not_writable', ['filePath' => $fullPath])); } @@ -139,7 +139,7 @@ class ImageService $name = str_replace(' ', '-', $name); $nameParts = explode('.', $name); $extension = array_pop($nameParts); - $name = implode('.', $nameParts); + $name = implode('-', $nameParts); $name = Str::slug($name); if (strlen($name) === 0) { @@ -190,8 +190,7 @@ class ImageService $thumbData = $this->resizeImage($storage->get($imagePath), $width, $height, $keepRatio); - $storage->put($thumbFilePath, $thumbData); - $storage->setVisibility($thumbFilePath, 'public'); + $storage->put($thumbFilePath, $thumbData, ['visibility' => 'public']); $this->cache->put('images-' . $image->id . '-' . $thumbFilePath, $thumbFilePath, 60 * 60 * 72); @@ -426,15 +425,4 @@ class ImageService $basePath = ($this->storageUrl == false) ? url('/') : $this->storageUrl; return rtrim($basePath, '/') . $filePath; } - - /** - * Returns a sanitized filename with only one file extension - */ - private function sanitizeFileName(string $fileName): string - { - $parts = explode('.', $fileName); - $extension = array_pop($parts); - - return sprintf('%s.%s', implode('-', $parts), $extension); - } }