需要一些帮助才能使我的图片可以点击。我已经尝试了一切,每当我做的图像打破,不会显示。代码是在网站上提供的,我试图添加分页到我的页面,现在发生另一个错误,点击图像和查看图像
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);
?>
答案 0 :(得分:2)
您没有在引号内正确转义变量:
echo '<a href="' . $urlPath . '/' . $image . '"><img src="' . $urlPath . '/' . $image . '" width="200" height="200" /></a>';
答案 1 :(得分:1)
类似的东西:
echo( "<a href='$dir/$file'><img width='200' height='200' src='$urlPath/$image'/></a>") ;
-your“&lt; a href ...”没有“&gt;”,那么它需要一个结束标记“&lt; / a&gt;”
-$ urlPath和$ image之间没有“/”(或者是$ urlPath字符串中的“/”?)