繁体   English   中英

PHP使图像可点击

[英]php making images clickable

需要一些帮助,使我的图片可点击。 我已经尝试了所有方法,每当我这样做时,图像都会破裂并且不会显示。 该代码是在网站上提供的,我试图在页面上添加分页,现在单击图像并捕获图像时发生另一个错误

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 "&nbsp;".($i+1); 
  else :
    print "&nbsp;<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>';

就像是:

echo( "<a href='$dir/$file'><img width='200' height='200' src='$urlPath/$image'/></a>") ;

-您的“ <ahref..."没有">”,则需要一个结束标记“ </a>”
-$ urlPath和$ image之间没有“ /”(或$ urlPath字符串中的“ /”?)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM