我在网页编码新的,我有问题分页列出的文件...从目录
现在我可以addapt列出,并从目录相呼应的图像,以显示他们的代码灯箱。
眼下代码显示所有图像从目录中,在5个图像的行,但无极限......
我怎么能我的代码更改显示的结果,可以说,例如:只有一行,每页有5个图像。然后显示通常的“页面:1,2,3 ...下一个...”我真的不知道该怎么做...我一直在尝试很多事情,但没有成功......
代码如下:
<?php
$page = $_SERVER['PHP_SELF'];
// How many images per row
$maxCols = 5;
// Directory where the albums are stored
$base = "albums";
// Get album title
$get_album = $_GET['album'];
if (!$get_album)
{
$handle = opendir($base);
echo "<div id='albums' class='imageRow'>";
while (($file = readdir($handle))!==FALSE)
{
if (is_dir($base."/".$file) && $file != "." && $file != "..")
{
//$list []= $file;
$img = $file.".jpg"; //Main image from each album.
echo "<div class='image'><a href='$page?album=$file'><img src='thumbnails.php?img=$base/$img' alt='$file' /></a><div class='album'><i>$file</i></div></div>";
}
}
echo "</div>";
closedir($handle);
//$total = count($list);
}
else
{
if (!is_dir($base."/".$get_album) || strstr($get_album,".")!=NULL || strstr($get_album,"/")!=NULL || strstr($get_album,"\\")!=NULL)
{
echo "Album doesn't exist.";
echo "<p /><a href='$page'>Back to albums</a>";
}
else
{
$count = 0;
$handle = opendir($base."/".$get_album);
echo "<div id='images' class='imageRow'>";
while (($file = readdir($handle)) !== FALSE)
{
if ($file != "." && $file !== "..")
{
echo "<div class='image'><a href='$base/$get_album/$file' rel='lightbox[1]' title='$file'><img src='thumbnails.php?img=$base/$get_album/$file' alt='$file' /></a></div>";
$count++;
if($count == $maxCols)
{
echo "</div>";
echo "<div id='images' class='imageRow'>";
$count = 0;
}
$list[] = $file; //Assign the images to a list to allow count.
}
}
echo "</div>";
closedir($handle);
$total = count($list); //Total elements at the album.
//echo "<a href='$page'>Back to albums</a>";
}
}
?>
任何帮助将不胜感激!
非常感谢提前!
试试这个http://www.codehive.net/PHP-Array-Pagination-10.html – Cups 2012-08-13 17:17:45
感谢您的回答,我似乎无法使用该代码来达到我的目的,我可以对此进行分页,但仍然显示我的目录中的每个文件。 – qalbiol 2012-08-13 19:34:41