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.