Parallel Thumbnail Generation
This commit is contained in:
parent
6215ab9f5b
commit
b175d77c7b
3 changed files with 37 additions and 12 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
// Classes
|
// Classes
|
||||||
require_once('lib/helpers.class.php');
|
require_once('lib/helpers.class.php');
|
||||||
require_once('lib/thumbs.class.php');
|
|
||||||
require_once('lib/template.class.php');
|
require_once('lib/template.class.php');
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
|
@ -10,9 +9,7 @@ require('conf/config.php');
|
||||||
|
|
||||||
// Prepare Some Basic Variables
|
// Prepare Some Basic Variables
|
||||||
$imagedir = Helpers::end_dir($conf['fs_imagedir']);
|
$imagedir = Helpers::end_dir($conf['fs_imagedir']);
|
||||||
$thumbdir = Helpers::end_dir($conf['fs_thumbdir']);
|
|
||||||
$imageurl = Helpers::end_dir($conf['web_imagedir']);
|
$imageurl = Helpers::end_dir($conf['web_imagedir']);
|
||||||
$thumburl = Helpers::end_dir($conf['web_thumbdir']);
|
|
||||||
|
|
||||||
$galleryname = $conf['gallery_name'];
|
$galleryname = $conf['gallery_name'];
|
||||||
|
|
||||||
|
@ -41,9 +38,6 @@ $secure = ($proto == 'https');
|
||||||
session_set_cookie_params([ 'lifetime' => 3600, 'path' => '/', 'domain' => $host, 'secure' => $secure, 'httponly' => true, 'samesite' => 'lax' ]);
|
session_set_cookie_params([ 'lifetime' => 3600, 'path' => '/', 'domain' => $host, 'secure' => $secure, 'httponly' => true, 'samesite' => 'lax' ]);
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
// Initialize Thumbnail Handler
|
|
||||||
$t = new Thumb(Helpers::end_dir($imagedir.$dir), $thumbdir, $thumburl, 200, 200);
|
|
||||||
|
|
||||||
// Filelist Cache Handling
|
// Filelist Cache Handling
|
||||||
$cdir = $dir;
|
$cdir = $dir;
|
||||||
if (empty($cdir))
|
if (empty($cdir))
|
||||||
|
@ -142,7 +136,7 @@ if (!empty($curfiles)| !empty($dirs)) {
|
||||||
} else {
|
} else {
|
||||||
$tmp['n'] = $image;
|
$tmp['n'] = $image;
|
||||||
$tmp['i'] = $index+1;
|
$tmp['i'] = $index+1;
|
||||||
$tmp['t'] = $t->get_thumb($image);
|
$tmp['t'] = 'thumb.php?d='.Helpers::end_dir($imagedir.$dir).'&i='.$image;
|
||||||
$data['images'][] = $tmp;
|
$data['images'][] = $tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
class thumb {
|
class thumb {
|
||||||
protected string $imagedir;
|
protected string $imagedir;
|
||||||
protected string $thumbdir;
|
protected string $thumbdir;
|
||||||
protected string $thumburl;
|
|
||||||
|
|
||||||
protected int $w = 200;
|
protected int $w = 200;
|
||||||
protected int $h = 200;
|
protected int $h = 200;
|
||||||
|
@ -26,10 +25,9 @@ class thumb {
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct($idir, $tdir, $turl, $width, $heigth) {
|
public function __construct($idir, $tdir, $width, $heigth) {
|
||||||
$this->imagedir = $idir;
|
$this->imagedir = $idir;
|
||||||
$this->thumbdir = $tdir;
|
$this->thumbdir = $tdir;
|
||||||
$this->thumburl = $turl;
|
|
||||||
$this->w = $width;
|
$this->w = $width;
|
||||||
$this->h = $heigth;
|
$this->h = $heigth;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +50,7 @@ class thumb {
|
||||||
if ($retval) {
|
if ($retval) {
|
||||||
return "img/video.png";
|
return "img/video.png";
|
||||||
} else {
|
} else {
|
||||||
return $this->thumburl.$dstname.'.jpg';
|
return $dstpath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +90,7 @@ class thumb {
|
||||||
imagedestroy($image);
|
imagedestroy($image);
|
||||||
imagedestroy($thumbnail);
|
imagedestroy($thumbnail);
|
||||||
}
|
}
|
||||||
return $this->thumburl.$dstname.'.jpg';
|
return $dstpath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
33
thumb.php
Normal file
33
thumb.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
// Load Helper Classes
|
||||||
|
require_once('lib/helpers.class.php');
|
||||||
|
require_once('lib/template.class.php');
|
||||||
|
require_once('lib/thumbs.class.php');
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
require('conf/config.php');
|
||||||
|
|
||||||
|
// Prepare Some Basic Variables
|
||||||
|
$thumbdir = Helpers::end_dir($conf['fs_thumbdir']);
|
||||||
|
$imagedir = Helpers::end_dir($conf['fs_imagedir']);
|
||||||
|
|
||||||
|
// Prepare Path Traversal Check
|
||||||
|
$r_basedir=realpath($imagedir);
|
||||||
|
|
||||||
|
$dir = $_GET['d'];
|
||||||
|
$img = $_GET['i'];
|
||||||
|
|
||||||
|
$r_imagedir = realpath($dir);
|
||||||
|
if ($r_imagedir === false || strpos(Helpers::end_dir($r_imagedir), $r_basedir.DIRECTORY_SEPARATOR) !== 0) {
|
||||||
|
$data['script'] = $_SERVER['PHP_SELF'];
|
||||||
|
$data['errormsg'] = 'A Path Traversal was Detected';
|
||||||
|
Template::view('tpl/error.html', $data);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize Thumbnail Handler
|
||||||
|
$t = new Thumb(Helpers::end_dir($dir), $thumbdir, 200, 200);
|
||||||
|
$thumbfile = $t->get_thumb($img);
|
||||||
|
|
||||||
|
header('Content-Type: image/jpeg');
|
||||||
|
readfile($thumbfile);
|
Loading…
Reference in a new issue