I am using an apache server on my desktop system as 127.0.0.1 and have php installed per the instructions.
Here is the code
The scandir function did not work as expected , which was to use the C:\Program Files\Apache Software Foundation\Apache2.2\htdocs folder as the default . Its what is shown for getcwd.
The html code works if I save the generated source and open it from windows explorer but not from apache.
Any suggestions are welcome and I am aware that this code is likely to be poor ;( but you have to start somewhere.
I have been extending it a little at a time so some stuff is not needed and commented out.
Thanks
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
function imgtype ($imgt)
{
$timg = "None";
if ($imgt == IMAGETYPE_GIF)
$timg = "Gif";
if ($imgt == IMAGETYPE_JPEG)
$timg = "Jpg";
if ($imgt == IMAGETYPE_PNG)
$timg = "Png";
if ($imgt == IMAGETYPE_BMP)
$timg = "Bmp";
if ($imgt == IMAGETYPE_PSD)
$timg = "Psd";
return $timg;
}
$dir = 'C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\photo';
chdir($dir);
$files1 = scandir(".");
foreach ($files1 as $fil) {
//if (is_dir($fil))
//echo "Dir: $fil <br>\n";
if (is_file($fil)) {
$fex = findexts($fil);
if ($fex != strtolower($fil))
//echo "File: $fil $fex <br>";
list($width, $height, $type, $attr) = getimagesize("$fil");
$imgt = imgtype($type);
//echo "$width $height $imgt $attr <br>";
$tmp = "photo\\".$fil ;
echo "<img src='$tmp' $attr ><br>\n";
}
}
?>
</body>
</html>