0
回答
PHP二级目录分页失败
科大讯飞通用文字识别100000次/天免费使用。立即申请   

现在有一个PHP写的目录直读程序,根目录可以做到翻页,但是二级目录翻页的时候还是显示根目录的页面,求大神帮忙改一下。

这个是index.php

<?php
define('WEBROOT', dirname(__FILE__));
require_once WEBROOT . '/config.php';
require_once WEBROOT . '/function.php';
//图片目录,相对主目录
$dir = ($_GET['imgdir'] == '') ? $root : $_GET['imgdir'].'/';
$os = PHP_OS;
if($os != 'WINNT') {
$dirmsg = explode("/", $dir);
$dirurl = array();
foreach($dirmsg AS $val) {
if($val) {
$dirurl[] = rawurlencode($val);
}
}
$rootdir = implode('/', $dirurl).'/';
} else {
$rootdir = $dir;
}
$list = getDirList($dir);
$imgArr = changeList($list);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="sysimg/css.css" />
<link rel="stylesheet" type="text/css" href="js/jquery.lightbox.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript"> LBox_path = "js/"; </script>
<script type="text/javascript">var $jLB = jQuery.noConflict();</script>
<script type="text/javascript" src="js/jquery.lightbox.js"></script>
<script type="text/javascript">$jLB(function(){$jLB('a[rel*=lightbox]').lightBox();});</script>
<title><?=$siteName?> - Powered by IsMole</title>
</head>
<BODY>
<div class="main">
<DIV id=image_rotator><IMG height=200 src="sysimg/picture.jpg" width=768>
</DIV>
<DIV id=nav_main>
<UL>
<LI class=home><A href="index.php">首页</A> </LI>
</UL>
</DIV>
<DIV id=content>
<?php showImgList($imgArr, $_GET['page'], $pageSize);?>
</DIV>
<DIV id="quicklinks">
<a href="javascript:history.back(-1)">返回上一页</a>
</div>
</BODY></html>


这个是config.php

$siteName = '我的相册';
//note:站点地址
$siteUrl = 'http://www.ismole.net';
//note:图片目录,相对于程序根目录
$root = 'images/';
$pageSize = 24;



这个是调用的函数 function.php

<?php
error_reporting(0);
// 归类文件夹和文件,按文件夹到文件顺序排列,普通显示
function changeList($array) {
global $dir,$rootdir;
if (is_array($array)) {
foreach($array AS $value) {
$os = PHP_OS;
if($os != 'WINNT') {
$url = rawurlencode($value);
} else {
$url = $value;
}
if(preg_match('/\.[png|gif|jpg|bmp]/', $value)) {
$htm .= "<li><a rel=\"lightbox\" href=\"".$rootdir.$url."\" target=\"_blank\"><img class=\"imgclass\" src=\"".$rootdir.$url."\" border=\"0\" width=\"100\" height=\"80\"><br />$value</a></li><hr>";
} elseif (preg_match('/\.[^png|gif|jpg|bmp]/', $value)) {
$htm2 .= "<li><a rel=\"lightbox\" href=\"?imgdir=".$rootdir.$url."\"><img src=\"".$root."sysimg/file.gif\" border=\"0\" width=\"100\" height=\"80\"><br />".$value."</a></li><hr>";
} else {
$htm3 .= "<li><a href=\"?imgdir=".$rootdir.$url."\"><img src=\"".$root."sysimg/dir.gif\" border=\"0\" width=\"100\" height=\"80\"><br />".$value."相册</a></li><hr>";
}
}
$html = '<div id="showimg"><ul>'.$htm3.$htm2 . $htm.'</ul></div>';

return $html;


// 显示图片列表及分页信息,普通显示
function showImgList($imgArr, $page, $pageSize) {
$li = explode('<hr>', $imgArr);
$total = count($li) - 1;
$page = ($page == '') ? 1 : $page;
$limit = ($total < $pageSize) ? $total : $pageSize;
$start = $pageSize * ($page - 1);
$show = array_slice($li, $start, $limit);
if($page != 1) {
$htm = '<div id="showimg"><ul>';
}
foreach($show AS $v) {
$htm.=$v;
}
$htm .='</ul></div>';
echo $htm;
echo multi($total, $pageSize, $page, '');



 


/* 获取文件夹列表 */
function getDirList($folder, $is_subdir = false, $i = 0) {
if (is_dir($folder)) {
$handle = opendir($folder);
while (false !== ($myfile = readdir($handle))) {
if ($myfile != "." && $myfile != "..") {
$fileTime[] = @filemtime($myfile);
$dirList[] = $myfile;
if ($is_subdir && is_dir($folder . "/" . $myfile)) {
getDirList($folder . "/" . $myfile, $is_subdir , $i + 1);


}
arsort($fileTime);
$newList = array();
foreach($fileTime AS $key=>$time) {
$newList[] = $dirList[$key];
}
closedir($handle);
unset($folder, $is_subdir);
return $newList;

return $newList;
}


//分页函数
function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = true, $simple = false) {
$multipage = '';
$mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
$realpages = 1;
if ($num > $perpage) {
$offset = 2;


$realpages = @ceil($num / $perpage);
$pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages;


if ($page > $pages) {
$from = 1;
$to = $pages;
} else {
$from = $curpage - $offset;
$to = $from + $page - 1;
if ($from < 1) {
$to = $curpage + 1 - $from;
$from = 1;
if ($to - $from < $page) {
$to = $page;

} elseif ($to > $pages) {
$from = $pages - $page + 1;
$to = $pages;




$multipage = ($curpage - $offset > 1 && $pages > $page ? '<a href="' . $mpurl . 'page=1" class="first"' . $ajaxtarget . '>1 ...</a>' : '') .
($curpage > 1 && !$simple ? '<a href="' . $mpurl . 'page=' . ($curpage - 1) . '" class="prev"' . $ajaxtarget . '>&lsaquo;&lsaquo;</a>' : '');
for($i = $from; $i <= $to; $i++) {
$multipage .= $i == $curpage ? '<strong>' . $i . '</strong>' :
'<a href="' . $mpurl . 'page=' . $i . ($ajaxtarget && $i == $pages && $autogoto ? '#' : '') . '"' . $ajaxtarget . '>' . $i . '</a>';



$multipage .= ($curpage < $pages && !$simple ? '<a href="' . $mpurl . 'page=' . ($curpage + 1) . '" class="next"' . $ajaxtarget . '>&rsaquo;&rsaquo;</a>' : '') .
($to < $pages ? '<a href="' . $mpurl . 'page=' . $pages . '" class="last"' . $ajaxtarget . '>... ' . $realpages . '</a>' : '') .
(!$simple && $pages > $page && !$ajaxtarget ? '<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=\'' . $mpurl . 'page=\'+this.value; return false;}" /></kbd>' : '');

$multipage = $multipage ? '</div><DIV id="quicklinks">' . (!$simple ? '<em>&nbsp;' . $num . '&nbsp;</em>' : '') . $multipage . '</div>' : '';

$maxpage = $realpages;
return $multipage;

?>




PHP
举报
叶无心
发帖于3年前 0回/120阅
顶部