简体   繁体   中英

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 "&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>';

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>"
-there's no "/" between $urlPath and $image (or is the "/" in the $urlPath string?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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