//
// //
// Demo showing basic usage of phpThumb in a photo gallery //
// //
//////////////////////////////////////////////////////////////
$docroot = realpath((getenv('DOCUMENT_ROOT') && ereg('^'.preg_quote(realpath(getenv('DOCUMENT_ROOT'))), realpath(__FILE__))) ? getenv('DOCUMENT_ROOT') : str_replace(dirname(@$_SERVER['PHP_SELF']), '', str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__))));
$basedir = '/demo/images/'; // webroot-relative path to main images directory (only this and subdirectories of this will be displayed)
$thumb = '/demo/phpThumb.php'; // webroot-relative path to "phpThumb.php"
$popup = '/demo/demo/phpThumb.demo.showpic.php'; // webroot-relative path to "phpThumb.demo.showpic.php" (only used if $use_popup == true)
$thumbnailsize = 120; // size of thumbnails in pixels when browsing gallery
$displaysize = 480; // size of large image display (popup or plain image) after clicking on thumbnail
$use_popup = true; // if true, open large image in self-resizing popup window; if false, display larger image in main window
//////////////////////////////////////////////////////////////
$dirlimit = realpath($docroot.'/'.$basedir);
$captionfile = $docroot.'/'.$basedir.(@$_REQUEST['dir'] ? $_REQUEST['dir'].'/' : '').'captions.txt';
if (file_exists($captionfile)) {
$filecontents = file($captionfile);
foreach ($filecontents as $key => $value) {
@list($photo, $caption) = explode("\t", $value);
$CAPTIONS[$photo] = $caption;
}
}
if (@$_REQUEST['pic']) {
$alt = @$CAPTIONS[$_REQUEST['pic']] ? $CAPTIONS[$_REQUEST['pic']] : $_REQUEST['pic'];
echo '.'&w='.$displaysize.'&h='.$displaysize).')
';
echo ''.htmlentities(@$CAPTIONS[$_REQUEST['pic']]).'
';
} else {
$currentdir = realpath($docroot.'/'.$basedir.@$_REQUEST['dir']);
if (!ereg('^'.preg_quote($dirlimit), $currentdir)) {
echo 'Cannot browse to "'.htmlentities($currentdir).'"
';
} elseif ($dh = @opendir($currentdir)) {
$folders = array();
$pictures = array();
while ($file = readdir($dh)) {
if (is_dir($currentdir.'/'.$file) && ($file{0} != '.')) {
$folders[] = $file;
} elseif (eregi('\.(jpe?g|gif|png|bmp|tiff?)$', $file)) {
$pictures[] = $file;
}
}
closedir($dh);
if (ereg('^'.preg_quote($dirlimit), realpath($currentdir.'/..'))) {
echo 'Parent directory
';
}
if (!empty($folders)) {
echo '';
}
if (!empty($pictures)) {
foreach ($pictures as $file) {
$alt = (@$CAPTIONS[$file] ? $CAPTIONS[$file] : $file);
echo '';
}
echo '
';
} else {
echo 'No pictures in "'.htmlentities(str_replace(realpath($docroot), '', realpath($docroot.'/'.$basedir.@$_REQUEST['dir']))).'"';
}
} else {
echo 'failed to open "'.htmlentities($basedir).'"';
}
}
?>