Php Programming Code Examples
Php > Graphics Code Examples
Show all images and related information
Show all images and related information
<?
/* If your image bin is not named "images", change the name below.
*/
$dir_name = "images";
$dir = opendir($dir_name);
// start the table:
$file_list = "<table>";
while ($file_name = readdir($dir)) {
// skip documents:
if (($file_name != ".") && ($file_name != "..")
&& (!preg_match("/.htm/i", "$file_name"))
&& (!preg_match("/.php/i", "$file_name")))
{
$file_list .= "<tr><td width=250><ul>
<li>name: <strong>$file_name</strong><br>";
$image_file = "$dir_name/$file_name";
$image_size = getimagesize($image_file, &$image_info);
while(list($key, $value) = each($image_size))
{
// make the output easier to read
switch($key){
case 0: $key = "<li>width: "; break;
case 1: $key = "<li>height: "; break;
case 2: $key = "<li>type: "; break;
case 3: $key = "<li>string:<br>"; break;
case bits: $key = "bits per sample:"; break;
}
if ($key == "type"){
switch($value){
case 1: $value = "GIF image"; break;
case 2: $value = "jpeg image"; break;
case 3: $value = "PNG image"; break;
}
}
$file_list .= ($key . $value . "<BR>\n");
}
// close that part of the table and make the next one for the image
$file_list .= "</ul></td><td>
<img src=\"$dir_name/$file_name\" $image_size[3]>
</td></tr><tr><td colspan=2><hr></td></tr>";
}
}
// finish the table
$file_list .= "</table>";
closedir($dir);
?>
<html>
<head><title>List of images</title></head>
<body background="rulerbackground.gif">
<h1>The images in "<? echo "$dir_name"; ?>"</h1>
<? echo "$file_list"; ?>
</body>
</html>