Files
MeDBia/videodb/vendor/james-heinrich/phpthumb/demo/phpThumb.demo.random.php
Malin f55c91276e feat: add videodb media index with Docker stack
- Add videodb PHP/MySQL media collection manager (Blu-ray, DVD, CD)
- Dockerfile: PHP 8.1 + Apache with GD/mysqli/exif extensions
- docker-compose.yml: app on port 6761 + MySQL 8.0 with health checks
- docker-entrypoint.sh: auto-generates config.inc.php from env vars,
  waits for MySQL, initializes DB schema idempotently
- init-db.php: CLI schema installer using app's own prefix_query() logic
- Persistent volumes for DB, cache, and cover images

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 09:49:52 +02:00

97 lines
3.6 KiB
PHP

<?php
//////////////////////////////////////////////////////////////
// phpThumb() by James Heinrich <info@silisoftware.com> //
// available at http://phpthumb.sourceforge.net //
// and/or https://github.com/JamesHeinrich/phpThumb //
//////////////////////////////////////////////////////////////
/// //
// phpThumb.demo.random.php //
// James Heinrich <info@silisoftware.com> //
// //
// Display a random image from a specified directory. //
// Run with no parameters for usage instructions. //
// //
//////////////////////////////////////////////////////////////
die('For security reasons, this demo is disabled by default. Please comment out line '.__LINE__.' in '.basename(__FILE__));
function SelectRandomImage($dirname='.', $portrait=true, $landscape=true, $square=true) {
// return a random image filename from $dirname
// the last 3 parameters determine what aspect ratio of images
// may be returned
$possibleimages = array();
if ($dh = opendir($dirname)) {
while ($file = readdir($dh)) {
if (is_file($dirname.'/'.$file) && preg_match('#\\.(jpg|jpeg|gif|png|tiff|bmp)$#i', $file)) {
if ($gis = @getimagesize($dirname.'/'.$file)) {
if ($portrait && ($gis[0] < $gis[1])) {
// portrait
$possibleimages[] = $file;
} elseif ($landscape && ($gis[0] > $gis[1])) {
// landscape
$possibleimages[] = $file;
} elseif ($square) {
// square
$possibleimages[] = $file;
}
}
}
}
closedir($dh);
}
if (empty($possibleimages)) {
return false;
}
if (PHP_VERSION < '4.2.0') {
mt_srand(time());
}
$randkey = mt_rand(0, count($possibleimages) - 1);
return realpath($dirname.'/'.$possibleimages[$randkey]);
}
if (@$_REQUEST['dir']) {
if (is_dir($_REQUEST['dir'])) {
if (!@$_REQUEST['o']) {
$_REQUEST['o'] = 'PLS';
}
$_REQUEST['o'] = strtoupper($_REQUEST['o']);
$portrait = (strpos(@$_REQUEST['o'], 'P') !== false);
$landscape = (strpos(@$_REQUEST['o'], 'L') !== false);
$square = (strpos(@$_REQUEST['o'], 'S') !== false);
$randomSRC = SelectRandomImage($_REQUEST['dir'], $portrait, $landscape, $square);
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$randomSRC = str_replace('\\', '/', preg_replace('#^'.realpath(@$_SERVER['DOCUMENT_ROOT']).'#i', '', realpath($randomSRC)));
} else {
$randomSRC = str_replace(realpath(@$_SERVER['DOCUMENT_ROOT']), '', realpath($randomSRC));
}
$otherParams = array();
foreach ($_GET as $key => $value) {
if (($key == 'dir') || ($key == 'o')) {
continue;
}
if (is_array($value)) {
foreach ($value as $vkey => $vvalue) {
$otherParams[] = urlencode($key).'['.urlencode($vkey).']='.urlencode($vvalue);
}
} else {
$otherParams[] = urlencode($key).'='.urlencode($value);
}
}
header('Location: ../phpThumb.php?src='.urlencode($randomSRC).'&'.implode('&', $otherParams));
exit;
} else {
echo htmlentities($_REQUEST['dir']).' is not a directory';
exit;
}
} else {
echo '<html><body>Usage: <b>'.basename($_SERVER['PHP_SELF']).'?dir=<i>&lt;directory&gt;</i>&amp;<i>&lt;phpThumb parameters&gt;</i></b>&amp;o=<i>(P|L|S)</i><br><br>Examples:<ul>';
echo '<li>'.basename($_SERVER['PHP_SELF']).'?./images/&o=L <i>(landscape images only)</i></li>';
echo '<li>'.basename($_SERVER['PHP_SELF']).'?./images/&o=PS <i>(portrait or square images only)</i></li>';
echo '</ul></body></html>';
}