CuDemVN.Wap.Sh



![]() | ![]() ![]() ![]() |
Filelist ảnh PHP có phân trang đầy đủ nhé chỉ cần up lên và trỏ vào đường dẫn thư mục ảnh thôi.
<?php
echo '<meta charset="UTF-8">';
// thu muc chua anh
$folder = 'img/';
$filetype = '*.*';
$files = glob($folder.$filetype);
// ham dem so files trong thu muc
$total = count($files);
// hien so anh o day
$per_page = 2;
// phan phan trang minh viet khong can phai quan tam
$last_page = (int)($total / $per_page);
if(isset($_GET["page"]) && ($_GET["page"] <=$last_page) && ($_GET["page"] > 0) ){
$page = $_GET["page"];
$offset = ($per_page + 1)*($page - 1);
}else{
$page=1;
$offset=0;
}
$max = $offset + $per_page;
if($max>$total){
$max = $total;
}
// function hien thu nut truoc - sau
function show_pagination($current_page, $last_page){
echo '<div>';
if( $current_page > 1 ){
echo ' <a href="?page='.($current_page-1).'"> Previous</a> - ';
}
if( $current_page < $last_page ){
echo ' <a href="?page='.($current_page+1).'"> Next</a> ';
}
echo '</div>';
}
echo "<li>Đang ở trang: $page offset</li>";
echo "<li>Tổng ảnh: $total</li>";
// chay vong lap hien thi anh
for($i = $offset; $i< $max; $i++){
$file = $files[$i];
$path_parts = pathinfo($file);
$filename = $path_parts['filename'];
echo '<p><a href="'.$file.'"><img src="'.$file.'" alt="'.$filename.'" width="200"></a></p>';
}
// nut phan trang
show_pagination($page, $last_page);
?>
Nguồn: KenAn

Đánh giá: 4.5/ 5, 611 bình chọn
