1

I made code using php in which it will display all the images in browser from specified path with define width and height. now I want to develop a code in which if I click on any of the image it should display me in original size in new window. please guide. don't know how to do it.

Edited Question

image.php

<script language="javascript"> //disabling right click
document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(event)
{
    if(event.button==2)
    {
        alert(status);
        return false;    
    }
}
</script>

<?php //displaying images on browser
$dir= '../images/';


$file_display = array('jpg','jpeg','png','gif');
if (file_exists($dir) == false) 
{
    echo 'Directory \''. $dir. '\' not found!';
}
else 
{
    $dir_contents = scandir($dir);

    foreach ($dir_contents as $file) 
    {
        $tmp = explode('.', $file);

        $f_e = end($tmp);
        $file_type = strtolower($f_e);

        if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) 
        {
            echo '<img src="'. $dir.$file. '" alt="'.$file. '"style="width:250px;height:250px" />';
        }
    } 
}
?>

this code will display all the images on browser, in browser if m clicking on any of the images that images should be displayed on new window.

How can I get image id of the clicked image?

chiwangc
  • 3,566
  • 16
  • 26
  • 32
Manjiri Parab
  • 141
  • 1
  • 16

3 Answers3

0

TRY this:

<a href="#" target="_blank"><img src="IMG URL" ></a>
Rajiv Choudhary
  • 141
  • 2
  • 14
0

you have the "target" attribute you can use it like that:

<a href=url to your picture target="_blank">Image in new window</a>

target = "_blank" will open the url in new window, try to fit that for what you want.

you can also put your image on top the 'a' attribute as "image link"

Developer
  • 460
  • 4
  • 17
0

echo '<a href="'. $dir.$file. '" target="_blank" title="'.$file. '"><img src="'. $dir.$file. '" alt="'.$file. '" style="width: 250px;height: 250px"></a>';

Just enclose the img with a link that "targets" a new window/tab.

If you know the url where the images are stored on the server and know the url to the location, you can specify that in the link:

For example: <a href="/images/'. $file. '" target="_blank" title="'.$file. '">

Anuga
  • 2,619
  • 1
  • 18
  • 27