[英]php making images clickable
Need a little help making my images clickable. 需要一些帮助,使我的图片可点击。 I've tried everything and whenever i do the images break and won't show.
我已经尝试了所有方法,每当我这样做时,图像都会破裂并且不会显示。 The code was provided on the site and i was trying to add pagination to my page and now another error occurs with click the images and seing the images
该代码是在网站上提供的,我试图在页面上添加分页,现在单击图像并捕获图像时发生另一个错误
while( $file = readdir( $open ) ){
$ext = strtoupper( pathinfo( $file, PATHINFO_EXTENSION ) );
if( in_array( $ext, $allow ) ){
$modifyTime = filemtime( $dir . $file );
$list[ $modifyTime ] = $file;
}
}
# reverse sort on key
krsort( $list );
$perPage = 20;
$total = count($list);
$pages = ceil($total/$perPage);
$thisPage = isset($_GET['pg'])?$_GET['pg']-1:0;
$start = $thisPage*$perPage;
echo "Page ";
// show pages
for ($i=0;$i<$pages;$i++):
if ($i==$thisPage) :
print " ".($i+1);
else :
print " <a href='?pg=".($i+1)."'>".($i+1)."</a>";
endif;
endfor;
// show images
$items = array_slice( $list, $start, $perPage );
foreach( $items as $image ){
echo "<a href='$dir/$file'<br/> " . $image . "<br/><img width='200' height='200' src='" . $urlPath . $image . "'/><br/></";
}
closedir($open);
?>
您没有在引号内正确地转义变量:
echo '<a href="' . $urlPath . '/' . $image . '"><img src="' . $urlPath . '/' . $image . '" width="200" height="200" /></a>';
Something like: 就像是:
echo( "<a href='$dir/$file'><img width='200' height='200' src='$urlPath/$image'/></a>") ;
-your "<a href..." has no ">", then it needs a closing tag "</a>" -您的“ <ahref..."没有">”,则需要一个结束标记“ </a>”
-there's no "/" between $urlPath and $image (or is the "/" in the $urlPath string?) -$ urlPath和$ image之间没有“ /”(或$ urlPath字符串中的“ /”?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.