2013-12-14 33 views
0

这里是我得到一个代码:如何在我的目录图片中添加链接?

<? 
include "top.php"; 
?> 
<center> 
<a href='upload.php'><button>Upload Image</button></a> 
</center> 
<br> 

<?php 


$www_root = 'http://annexsecurity.x10.mx/images'; 
$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) { 
     $file_type = strtolower(end(explode('.', $file))); 
     if (($file !== '.') && ($file !== '..') && (in_array($file_type,  $file_display))) { 
      echo '<img src="', $www_root, '/', $file, '" alt="', $file, '"/>'; 
     } 
    } 
} 
?> 

<style type="text/css"> 

    img { 
    height: 100; 
    width: 100; 
    float: left; 
    margin: 0.5em; 
    border: 1px solid #ccc; 
    padding: 1em; 
    font-size: 10px; 
    } 

</style> 

我所要做的是使它所以当你点击它会导致你的图像的更大版本的图像。像,完整的形象。例如,它会导致这样的事情:http://www.example.com/image.png/

有人可以帮我这个吗?这是显示图像的代码行:

echo '<img src="', $www_root, '/', $file, '" alt="', $file, '"/>'; 

现在,我想要链接的东西,因此它会导致更大的图像。

+0

SpiderLinked

+0

你想将用户重定向到具有比最初的一个或图像更大的页面你想在同一页面上弹出更大版本的初始图像? – SpiderLinked

+0

您还可以通过向图像添加单击事件来实现此“效果”。 (jquery) – SpiderLinked

回答

0

您可以依次进入链接中使用类似的语法来把图像链接到的图像<a href="http://example.com/image.png"><img src="imageSrcHere" alt="" /></a>

if (file_exists($dir) == false) { 
    echo 'Directory \''. $dir. '\' not found!'; 
} else { 
    $dir_contents = scandir($dir); 

    foreach ($dir_contents as $file) { 
     $file_type = strtolower(end(explode('.', $file))); 
     if (($file !== '.') && ($file !== '..') && (in_array($file_type,$file_display))) { 
      $imageLink = 'http://example.com/image.png'; //please write image url here. 
      echo '<a href="'.$imageLink.'"><img src="'. $www_root. '/'. $file. '" alt="'. $file. '"/></a>'; 
     } 
    } 
} 
+0

正确...但是这并不回答操作的问题...他问:“我如何添加一个链接到图像?” (大约) – SpiderLinked

+0

由于echo使用的是昏暗的 - 它们被视为单独的参数而不是拼接。 http://www.electrictoolbox.com/php-echo-commas-vs-concatenation/ – Pebbl

+0

@pebbl感谢宝贵的信息。 – Roopendra

相关问题