2个回答
展开全部
function listFiles($dir, $ext = '{*.jpg,*.JPG,*.gif,*.GIF,*.PNG,*.png}') {
$alldirs = array();
$dirs = glob($dir . '/'. $ext, GLOB_BRACE);//
if (count($dirs) > 0) {
foreach ($dirs as $d) {
$alldirs[] = $d;
}
}
return $alldirs;
}
function showImgFiles($imgFiles, $pageSize, $image = 'images') {
global $page;
$tempArr = array_chunk($imgFiles, $pageSize);
$k = $page - 1;
echo '<ul style="position: relative;left: -10px;list-style-type: none;width: 780px;overflow: hidden;">';
foreach ($tempArr[$k] as $file) {
echo '<li style="float: left;margin-right: 20px;margin-top: 20px;"><a href=""><img src="'.dirname($_SERVER['SCRIPT_NAME']) . DIRECTORY_SEPARATOR . $image . DIRECTORY_SEPARATOR . basename($file) .'" style="width: 100px;height: 100px;border: 1px solid #ccc" /></a></li>';
}
echo '</ul>';
echo '<div style="margin: auto;width: 200px; height: 50px;">';
for ($i = 1; $i < count($tempArr); ++$i) {
echo '<a href="?page='.$i.'">';
echo $i;
echo '</a>';
}
echo '</div>';
}
//$scriptName = $_SERVER['SCRIPT_NAME'];
$path = dirname(__FILE__).DIRECTORY_SEPARATOR.'images';//image file
$imgFiles = listFiles($path);//get all of the img files
$pageSize = 2;//每页显示数目
$totalAmt = count($imgFiles);//总共数目
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
showImgFiles($imgFiles, $pageSize);
$alldirs = array();
$dirs = glob($dir . '/'. $ext, GLOB_BRACE);//
if (count($dirs) > 0) {
foreach ($dirs as $d) {
$alldirs[] = $d;
}
}
return $alldirs;
}
function showImgFiles($imgFiles, $pageSize, $image = 'images') {
global $page;
$tempArr = array_chunk($imgFiles, $pageSize);
$k = $page - 1;
echo '<ul style="position: relative;left: -10px;list-style-type: none;width: 780px;overflow: hidden;">';
foreach ($tempArr[$k] as $file) {
echo '<li style="float: left;margin-right: 20px;margin-top: 20px;"><a href=""><img src="'.dirname($_SERVER['SCRIPT_NAME']) . DIRECTORY_SEPARATOR . $image . DIRECTORY_SEPARATOR . basename($file) .'" style="width: 100px;height: 100px;border: 1px solid #ccc" /></a></li>';
}
echo '</ul>';
echo '<div style="margin: auto;width: 200px; height: 50px;">';
for ($i = 1; $i < count($tempArr); ++$i) {
echo '<a href="?page='.$i.'">';
echo $i;
echo '</a>';
}
echo '</div>';
}
//$scriptName = $_SERVER['SCRIPT_NAME'];
$path = dirname(__FILE__).DIRECTORY_SEPARATOR.'images';//image file
$imgFiles = listFiles($path);//get all of the img files
$pageSize = 2;//每页显示数目
$totalAmt = count($imgFiles);//总共数目
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
showImgFiles($imgFiles, $pageSize);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询