// Image list script
// Description: Generates an HTML document with all of the images found in
// the current directory.
// Author: Michael Hansen
// For: CS471
// Defaults:
$width = 0;
$height = 0;
$cols = 1;
// Load user-specified settings:
if (isset($_GET['width']))
$width = $_GET['width'];
if (isset($_GET['height']))
$height = $_GET['height'];
if (isset($_GET['cols']))
$cols = $_GET['cols'];
// Get the script's filename, the current timestamp, and the current directory
$myname = basename($_SERVER['PHP_SELF']);
$now = date("r");
$dirname = getcwd();
// Start writing the document to the browser window
echo "\n".
"
\n".
" $dirname\n".
" ".
" \n".
" \n".
" \n".
"\n".
"\n".
" $myname: $dirname
\n".
" $now
\n".
"
\n".
" \n";
// Keep track of columns
$curcol = 0;
// Allowed file extensions:
$imgexts = array('jpg', 'jpeg', 'png', 'gif');
// Start scanning the directory
$dir = opendir($dirname);
echo " \n";
while (($filename = readdir($dir)) !== false) {
// Make sure we want this file type
$ext = strtolower(end(explode('.', $filename)));
if (in_array($ext, $imgexts)) {
if ($curcol >= $cols) {
// Time to start a new row
echo "
\n";
$curcol = 0;
}
echo "  \n"; // Finish the tag
// Display some info about the image
$filesz = round(filesize($filename) / 1024, 2);
echo "$filename Size: $filesz KB | \n";
$curcol++;
}
}
closedir($dir);
// Make sure the table is valid by adding blank cells
if ($curcol != 0) {
while ($curcol < $cols) {
echo " | \n";
$curcol++;
}
}
echo "
\n";
// Finish the document
echo "
\n".
"\n".
"";
?>