簡體   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