Lucky
Lucky

Reputation: 209

PHP variable as input for img src attribute

I am trying to make gallery which displays all the .jpg files in some local directory, but it makes me problem.

   <?php

   $directory = "img/";   
   $images = glob($directory."*.jpg");
   foreach($images as $image)
   {
       echo '<img src="file://'.$image.'" /><br />'
   }
   ?>

Somehow path to jpg file is not correctly passed to the src attribute, where I am wrong?

Upvotes: 0

Views: 146

Answers (1)

mrJ0ul3
mrJ0ul3

Reputation: 126

Just remove the file:// on the src.

from

echo '<img src="file://'.$image.'" /><br />';

to

echo '<img src="'.$image.'"/><br />';

Upvotes: 1

Related Questions