From c16fed9b508c6dc11baed5dbe3a5fe435c4d326c Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 30 Dec 2018 18:39:30 +0100 Subject: [PATCH] Improve thumbnail creation --- application/controllers/File.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/application/controllers/File.php b/application/controllers/File.php index 99f2da0..27bdaa0 100644 --- a/application/controllers/File.php +++ b/application/controllers/File.php @@ -25,14 +25,25 @@ class File extends MY_Controller header("Content-Disposition: attachment; filename=" . $file['name'] . '.' . explode('/', $file['type'])[1]); } - $imagePath = 'files' . DIRECTORY_SEPARATOR . - ($file['isUserData'] ? 'userContent' . DIRECTORY_SEPARATOR : '') . - (isset($_GET['w']) || isset($_GET['h']) ? 'thumbs' . DIRECTORY_SEPARATOR : '') . - $file['name'] . (isset($_GET['w']) ? '_w' . $_GET['w'] : '') . - (isset($_GET['h']) ? '_h' . $_GET['h'] : '') . '.' . - explode('.', $file['path'])[1]; + $isThumb = isset($_GET['w']) || isset($_GET['h']); + $w = isset($_GET['w']) ? $_GET['w'] : false; + $h = isset($_GET['h']) ? $_GET['h'] : false; + $imagePath = pathinfo($file['path'], PATHINFO_DIRNAME) . '/' . + ($isThumb ? 'thumbs/' : '') . + $file['name'] . + ($w ? '_w' . $w : '') . + ($h ? '_h' . $h : '') . + '.' . pathinfo($file['path'], PATHINFO_EXTENSION); if (!file_exists($imagePath)) { + if(!$isThumb) + exit; + + $dir = pathinfo($imagePath, PATHINFO_DIRNAME); + if(!file_exists($dir)) { + mkdir(pathinfo($dir, 0777)); + } + $config['image_library'] = 'gd2'; $config['source_image'] = $file['path']; if (isset($_GET['w'])) {