From 006717a3ccb0b789fbdf03bb1363558c59e4018b Mon Sep 17 00:00:00 2001 From: Marijn Kampf Date: Fri, 20 Nov 2015 08:06:50 +0000 Subject: [PATCH] Fix Fatal error on invalid image If user has uploaded an invalid image the original code would crash when called from template --- forms/UploadField.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/forms/UploadField.php b/forms/UploadField.php index 41485b489..e19c90afe 100644 --- a/forms/UploadField.php +++ b/forms/UploadField.php @@ -870,11 +870,13 @@ class UploadField extends FileField { $width = $this->getPreviewMaxWidth(); $height = $this->getPreviewMaxHeight(); if ($file->hasMethod('getThumbnail')) { - return $file->getThumbnail($width, $height)->getURL(); + $r = $file->getThumbnail($width, $height); + if ($r) return $r->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($width, $height); } elseif ($file->hasMethod('Fit')) { - return $file->Fit($width, $height)->getURL(); + $r = $file->Fit($width, $height); + if ($r) return $r->getURL(); } else { return $file->Icon(); }