Quickie PHP script worked once

I snaffled a little script to print the contents of a directory on the screen

if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "$file\

Then altered it to look in an images directory and load this as a background with CSS. Worked great–once. Then it wouldnt work again.

If I view source, I see the xHTML/CSS dynamically change with the file name I swap into the directory.

What gives?

Also I used the WebDev toolbar to turn off Cache.

I’d still like to see said modified code…

When you say “worked once” do you mean it works every “first time” (i.e. intial page load but not after clicked) or it only worked the first time you tried the new modified code?

No C drive as I’m *nix/AMP.

As far as the code…well…that’s really it. Other than replacing the echo statement with a new var
$MyFile = $file;
And printing $MyFile in the url() of a css background-image.

I struggled with the var in the CSS for a while cuz $file was not available outside the if statement. When I put it into the new var $MyFile the page loaded, once.

My first thought was there is some special order in the behaviour of the browser loading the various bits (PHP, xHTML, CSS, images).

The goal is simple. I’m testing some images on a xHTML page. Rather then change my xHTML every time, I worked out this scriptie to get the file name and paste it into the CSS. Then I put the image in the background of the body and stuck a link to another page in a div set 100%. The background is clickable to the next page and vice-versa. Then I can compare the images without having to rewrite the code.

I could find another way to do this with JavaScript, but I’m learn’n PHP and (better) CSS. The friggn source shows the code changed and the cache is turned off in Moz. I’m stumped.

Post the code you’re -actually- having trouble with (not the example you started from), and perhaps we’ll be able to give you a better suggestion…

use the full path to the directory:


$handle = opendir('c:\\apache\\htdocs\	est')