1

如何a href link在每个不同的图像上使用多个不同的?并且图像是从`文件夹或目录中获取的?

php代码

<?php 

$directory = "data/uploads/bottomslider/";

if (glob($directory . "*") != false)
{

$filecount = count(glob($directory . "*"));

}
$files_index = glob("data/uploads/"."bottom"."slider/*.*");

for ($i=0; $i<$filecount; $i++)
{
$num2 = $files_index[$i];

?>  

<li class="jcarousel-item"><a href=""><img src="<?php echo $num2;?>" 
style="height: 119px!important; width:132px !important;"/></a></li>

<? }?>

例如

i want like this?

<a href="google.com">Image1</a>
<a href="facebook.com">Image2</a>
<a href="yahoo.com">Image2</a>
4

2 回答 2

1

我没有测试代码。但这应该有效。假设文件夹“数据”位于您网页的根目录中。

$directory = "data/uploads/bottomslider/";
if(file_exists($directory)) {
    $files = scandir($directory);
    $output = "";
    foreach($files as $key => $value) {
        if($value != '.' && $value != '..' && $value != '.quarantine' && $value != '.tmb') {
            $output .= '<li class="jcarousel-item"><a href="/'.$directory.$value.'"><img src="/'.$directory.$value.'"
style="height: 119px!important; width:132px !important;"/></a></li>';
        }
    }
    //$output contains all the images.
    echo $output;
}
于 2013-10-07T12:38:53.750 回答
0
<?php 

$directory = "data/uploads/bottomslider/";
$link = "";
if (glob($directory . "*") != false)
{
    $filecount = count(glob($directory . "*"));
}
$files_index = glob("data/uploads/"."bottom"."slider/*.*");
//this array must be same size like number of images 
$array1 = array('www.yahoo.com', 'www.google.com', 'www.facebook.com', 'www.stackovrflow.com', 'www.blahblah.com');
for ($i=0; $i<$filecount; $i++)
{
    $num2 = $files_index[$i];
    $link = $array1[$i];

?>  

<li class="jcarousel-item"><a href="<?php echo $link?>"><img src="<?php echo $num2;?>" 
style="height: 119px!important; width:132px !important;"/></a></li>

<?php
}
?>

提供完整的链接路径,例如“ https://www.facebook.com/

于 2013-10-07T12:51:53.193 回答