这是我当前的php脚本,它将文件夹中的所有图像显示到表中。但是,有很多图像,加载时间非常慢。如何限制显示的图像数量并创建动态导航功能?谢谢!
<?php
$files = glob("images/*.*");
for ($i = 1; $i < count($files); $i++) {
$image = $files[$i];
$supported_file = array(
'gif',
'jpg',
'jpeg',
'png'
);
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
if (in_array($ext, $supported_file)) {
echo '<td><a href="' . $image . '"><img src="' . $image . '" alt="Random image" width=200 /></a></td>';
}
if ($i % 5 === 0) {
echo "</tr><tr>";
}
}
?>
答案 0 :(得分:0)
您还可以将$files
变量保存在$_SESSION
数组中。像
if (empty($_SESSION['files'])) {
$files = glob("images/*.*");
... code for cleaning the $files array based on extension ...
$_SESSION['files'] = $files;
} else {
$files = $_SESSION['files'];
}
然后检查$files
的大小,并根据您想要的大小创建链接。
<a href="/whatever?page=2">2</a>
然后使用$_GET['page']
变量确定要显示的所需图像集。