gpt4 book ai didi

php - 如何在我的目录图片中包含一个链接?

转载 作者:行者123 更新时间:2023-11-28 11:43:30 25 4
gpt4 key购买 nike

这是我得到的代码:

<?
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, '"/>';

现在,我想要那里的链接,这样它会导向更大的图像。

最佳答案

您可以链接到图片 <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>';
}
}
}

关于php - 如何在我的目录图片中包含一个链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20582532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com