PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The problem is most likely in the code above the foreach loop - parse errors are reported for the line where PHP could no longer continue processing which is generally not the line in which the error exists.
twigletmac wrote:The problem is most likely in the code above the foreach loop - parse errors are reported for the line where PHP could no longer continue processing which is generally not the line in which the error exists.
Mac
i noticed that. aside from how i create the array (which according tot he book is correct) i did the foreeach just like the book.
i have two sub directories i make to test this. once i get this working i have a different page i'm making to make the galleries.. my mother wants a way to share photos with people and i figured since she keeps complaining i should make something quick to silence her and forcing her to put them in sub directories would be the easiest thing to do.
this is the function to make the list of galleries. each sub directory becomes a list.
function gallist(){ // should be a list of subdirectories
echo "<html><body bgcolor="#000000" text="#ffffff"><center><p>the galleries are...\n<br>";
// get directories
$dirs=array(); // empty directory array
$d=opendir(getcwd()) or die($php_errormsg); // open the current directory
while(false !==($f=readdir($d))){ // read what's in the directory
$posdir=$d.'/'.$f; // make it the full working path
if(is_dir($posdir)){ // if it's a directory
$dirs[] = $f; // add it to the list
}
}
$dirs=sort($dirs);
// iterate though the list of directories making links calling gallery.php?dir=$dir
foreach($dirs as $dir){
echo "<a href="gallery.php?dir=$dir" target="display">$dir</a>\n<br>";
}
echo "</body></html>";
}
$d isn't the directory name or path, instead its a resource.
so I replaced it with:
$posdir = $f;
ie. the relative filename, and it should print out the correct directories..
Learn how to debug your code by printing out your variables as your script runs, a simple problem like this could have been solved easily with this process, eg. echo $posdir; in the while() loop, or a echo "Adding to dirs[] array $f"; in the is_dir($posdir) statement