Archived
1
0

Improve thumbnail creation

This commit is contained in:
Marcel 2018-12-30 18:39:30 +01:00
parent 28370a9902
commit c16fed9b50

View File

@ -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'])) {