Any ideas why this php code adaption doesn't work?

iRant

New member
I'm using something similar to the following code (with thanks to ratchetr) to display images in the jpg directory:

<?php
//path to directory to scan
$directory = "jpg/";

//get all image files with a .jpg extension.
$images = glob($directory . "*.jpg");

//print each file name
foreach($images as $image)
{
echo '<img src="' . $image . '" alt="pictures from Members" />';
}
?>


When I change the directory to something with a ../ at the start, it's OK but if I use a slash / to indicate start in web root, the php doesn't return anything.

The following html is OK - the slash at the start makes the browser look in images folder in web root - but when php serves it in this case, it doesn't work:

<img src="/image-folder/pictures/foo.jpg" />

Weird?



(NOTE: I tried using DOCUMENT_ROOT but realised how silly that was inside an IMG tag after a while, lol)
 
Back
Top