Reputation: 47
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);
?>
Upvotes: 0
Views: 237
Reputation: 1137
You're not escaping your variables properly within the quotes:
echo '<a href="' . $urlPath . '/' . $image . '"><img src="' . $urlPath . '/' . $image . '" width="200" height="200" /></a>';
Upvotes: 2
Reputation: 804
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?)
Upvotes: 1