PHP onClick

Hi!

So I’m trying to build a lightweight image gallery.

I’m trying to show all pictures from a specific directory and have it so when a user clicks on the picture it opens a new window with the high res picture.

This is my code:

<?php

   $files = glob("images/*.*");

   for ($i=1; $i<count($files); $i++)

  {

  $image = $files[$i];
  
  
  echo '<div class="img"><a href="#" onClick="window.open(\'.$image .\', \'width=600\', \'height=400\', \'scrollbars=no\', \'menubar=no\');"><img width="160" height="140" src="'.$image .'"></a></div>';

  
  ;
   }

Problem I’m having is probably VERY easy to fix, but I can’t figure it out.

When it opens the new window instead of linking to the picture I’m trying to open, it has www.root.com/.$image%20 as the path…

What am I missing here? Why won’t it give the actual path to the image? On the main gallery.php page the images show up fine, and if I put the .$image . code in the href="" tag it works as well.

Any tips would be appreciated!

You don’t actually break out of the single quotes in the PHP string to have $image concatenated. Also you probably need to add images/ to the location:

[php]echo ‘

’;[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service