I have some code to pull images and show in a frame within the browser.
I would like to centre the image selected and set the width and height.
The code is PHP.
I'm new to web programming so be gentle please.
Code: Select all
<?php
error_reporting(0);
?>
<?PHP
function getFileList($dir)
{
// array to hold return value
$retval = array();
// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";
// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
// skip hidden files
if($entry[0] == ".") continue;
if(is_dir("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry/",
"type" => filetype("$dir$entry"),
"size" => 0,
"lastmod" => filemtime("$dir$entry")
);
} elseif(is_readable("$dir$entry")) {
$retval[] = array(
"name" => "$dir$entry",
"size" => filesize("$dir$entry"),
"lastmod" => filemtime("$dir$entry")
);
}
}
$d->close();
return $retval;
}
?>
<?PHP
$dirlist = getFileList(".");
// output file list as HTML table
echo "<table border=\"1\"> \n";
echo "<tr><th>All Documents To View</th></tr>\n";
foreach($dirlist as $file) {
if(!preg_match("/\.pdf$/", $file['name'])) continue;
echo "<tr>\n";
echo "<td><a href=\"{$file['name']}\" target=\"inner\">{$file['name']}</a></td>\n";
echo "</tr>\n";
}
echo "</table><br>";
?>
<?php
//path to directory to scan. i have included a wildcard for a subdirectory
$directory = "";
//get all image files with a .jpg extension.
$images = glob("" . $directory . "*.jpg");
$imgs = '';
// create array
foreach($images as $image){ $imgs[] = "$image"; }
//shuffle array
shuffle($imgs);
//select first 12 images in randomized array
$imgs = array_slice($imgs, 0, 150);
//display images
foreach ($imgs as $img) {
echo "<a href=\"$img\" target=\"inner\"><img src='$img' width=\"80\" border=\"1\"/></a> ";
}
?>