> Can you actually put UNIX command line code in the middle of a PHP script like that and have it execute? The line in question is this:
> $x=explode("\n",cd $dir; ls *.jpg *.png *.gif);
Actually, my example had backticks around the Unix commands but I guess that's one of the magic characters here and got stripped.
And I was wrong about shell_exec() - I confused it for escapeshellcmd(), which provides some protection against malicious user input. shell_exec() is functionally equivalent to using backticks so is probably preferable.
Re: 302 - I was mistaken to include it. I was trying to match waha's perl example and I actually never used it before. PHP automatically prepends an Status: 302 if you call a header("Location:"), so while it doesn't really hurt to do so explicitly, it's not necessary.
If you want to call a "Location:" header with another status code (say, a 301 which indicates permanent relocation), then you should call that header separately.