【发布时间】:2016-11-17 23:47:41
【问题描述】:
我使用 php 编写了代码,它将在浏览器中显示来自指定路径的所有图像,并定义了宽度和高度。现在我想开发一个代码,如果我单击任何图像,它应该在新窗口中以原始大小显示我。请指导。不知道怎么弄。
已编辑的问题
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" />';
}
}
}
?>
此代码将在浏览器中显示所有图像,如果我单击任何应在新窗口中显示图像的图像,则在浏览器中。
如何获取点击图片的图片id?
【问题讨论】:
-
你试过window.open吗?
-
在 window.open 中写什么。我的意思是在浏览器中它向我显示所有图像然后我如何获取它们的图像名称然后将其发送到另一个页面。
-
不清楚你想要什么。向我们展示你到目前为止所拥有的......也许这会让你想要什么。展示您如何在页面上加载图片。
-
好的,我正在编辑我的问题
-
使用
src属性打开图片。像这样echo '<img onclick="window.open(this.src);" src="'. $dir.$file. '" alt="'.$file. '"style="width:250px;height:250px" />';或分配一个类名并为其编写事件函数。
标签: javascript php