topical media & game development
professional-sql-07-public-files-index.php / php
<?php
// include shared code
include '../lib/config.php';
// accept incoming parameters
_GET['album'])) ? album_p = BASEDIR . '/' . file = (isset(_GET['file'] : '';
album_p . '/' . album && album_p), BASEDIR) !== 0 ||
strpos(realpath(file_p))
{
header('Location: ' . htmlspecialchars(_SERVER['PHP_SELF']) . '?album='.
urlencode(album) .
'</a></p>';
switch (substr(file, '.') + 1))
{
// jpeg files are included using the img element
case 'jpg':
case 'jpeg':
echo '<img src="view.php?file=' . urlencode(file) . '" alt="' . htmlspecialchars(album . '/' . album . '/' . album . '/' . _SERVER['PHP_SELF']));
exit();
}
album)
{
// redirect to album list if album does not exist or is outside the
// allowed base directory
if (strpos(realpath(album_p))
{
header('Location: ' . htmlspecialchars(_SERVER['PHP_SELF']) . '">' .
'< Back to album index</a></p>';
// retrieve album description if available
if (file_exists(album_p . '/desc.txt')) . '</p>';
}
// read in list of image and QuickTime files
album_p);
f = basename(readdir(f == '.' || f))
{
f, strpos(ext == 'jpg' || ext == 'mov')
{
f;
}
}
}
closedir(images);
//display thumbnails in a table
columns = 7;
echo '<table border="1">';
foreach (image)
{
if (0 == (columns))
{
echo '<tr>';
}
echo '<td style="width: '. (100 / _SERVER['PHP_SELF']),
urlencode(image),
urlencode(image),
htmlspecialchars(counter % counter++ % GLOBALS['TEMPLATE']['content'] = ob_get_contents();
ob_end_clean();
}
// generate default view showing list of available albums
else
{
ob_start();
// retrieve list of albums
dir = opendir(BASEDIR);
while(dir)))
{
if(f == '..') continue;
if (is_dir(BASEDIR . '/' . albums[] = dir);
// sort albums
natcasesort(albums as _SERVER['PHP_SELF']),
urlencode(album));
}
echo '</ul>';
album = (isset(_GET['album'] : '';
album;
_GET['file'])) ? file_p = file;
// generate image view
if (file)
{
// redirect to album list if album or file is outside allowed base
// directory or does not exist
if (strpos(realpath(file_p), BASEDIR) !== 0 || !file_exists(_SERVER['PHP_SELF']));
// exit();
echo _SERVER['PHP_SELF']) . '?album='.
urlencode(album) .
'</a></p>';
switch (substr(file, '.') + 1))
{
// jpeg files are included using the img element
case 'jpg':
case 'jpeg':
echo '<img src="view.php?file=' . urlencode(file) . '" alt="' . htmlspecialchars(album . '/' . album . '/' . album . '/' . _SERVER['PHP_SELF']));
exit();
}
album)
{
// redirect to album list if album does not exist or is outside the
// allowed base directory
if (strpos(realpath(album_p))
{
header('Location: ' . htmlspecialchars(_SERVER['PHP_SELF']) . '">' .
'< Back to album index</a></p>';
// retrieve album description if available
if (file_exists(album_p . '/desc.txt')) . '</p>';
}
// read in list of images
album_p);
f = basename(readdir(f == '.' || f))
{
f;
}
}
closedir(images);
//gather thumbnails
foreach (image)
{
switch (substr(image, '.') + 1))
{
case 'jpg':
case 'jpeg':
case 'mov':
printf ('<a href="\%s?album=\%s&file=\%s"><img ' .
'src="thumbnail.php?file=\%s" alt="\%s"/></a> ',
htmlspecialchars(album),
urlencode(album . '/' . image));
break;
}
}
albums = array();
f = basename(readdir(f == '.' || f))
{
f;
}
}
closedir(albums);
// display album list
echo '<p>Albums</p>';
echo '<ul>';
foreach (album)
{
printf('<li><a href="\%s?album=\%s">\%s</a></li>',
htmlspecialchars(album),
htmlspecialchars(GLOBALS['TEMPLATE']['content'] = ob_get_contents();
ob_end_clean();
}
// display the page
*/// include '../templates/template-page.php';
echo
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.