Hello Everyone!
I have a would be simple little script that is supposed to read images in a file, and read them into a browser dynamically. Here is the code:
[hr width=100%]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Project Me</title>
</head>
<style type="text/css">
ul {list-style-type: none;
}
li {float: left;
padding:10px;
margin: 10px;
font: bold 10px Tahoma
}
img {display: block;
border:1px solid #333300;
margin-bottom:5px;
}
</style>
<body>
<h5>Picute Perfect Project</h5>
<ul>
<?php
// define location of photo images
// this must be a locaiton accessible by the script owner
$photosDir = './photos';
// define which file extensions are images
$photosExt = array('gif','jpg','jpeg','tif','tiff','bmp','png',);
// initalize array to hold filenames of images found
$photosList = array();
// read directory contents
// build photo list
if (file_exists($photosDir)){
$dp = opendir($photosDir) or die ('Error: Cannot open directory');
while ($file = readdir($dp)){
if ($file != '.' && $file != '..') {
$fileData = pathinfo($file);
if (in_array($fileData['extension'], $photosExt)){
$photosList[] = "$photosDir/$file";
}
}
}
closedir($dp);
} else {
die ('Error: Directory does not exist.');
}
// iterate over photo list
// display each image and filename
if (count($photosList)) > 0) {
for ($x=0; $x<count($photosList); $x++){
?>
<li>
<img height="150" width="200" src="<?php echo $photosList[$x]; ?>" />
<?php echo basename($photoList[$x]); ?><br />
<?php echo round(filesize($photosList[$x])/1024) . ' KB'; ?>
</li>
<?php
}
} else {
die('Error: No images found in directory');
}
?>
</ul>
</body>
</html>
I believe the problem is at the very end ... when it is trying to read
if (count($photosList)) > 0) {
for ($x=0; $x<count($photosList); $x++){
This is line 47.
I don't know if $photoList is even creating an array or not. I have not seen enough behaviors of closedir() ither to tell if this is the problem. I know this is a simple read and write issue. There is no real explanation or Error message ...just, error at line 47 and the path. I ran a 'realpath()' also to make sure the directory was correct.
Parse error: parse error in C:\xampp\htdocs\ferlic.proj\new.site\photos\gallery.php on line 47
I am giving alot of detail on this because it is a very simple issue that will be used to solve several scripts.