$allowed_types=array('jpg','jpeg','gif','png'); if($pa==1){ $dir ="gallery/congra54/"; }elseif($pa==2){ $dir ="gallery/safari54/"; }elseif($pa==3){ $dir ="gallery/meting_bos/"; } $files1 = scandir($dir); $total=0; // นับจำนวนรูปทั้งหมด $pic_path=array(); foreach($files1 as $key=>$value){ if($key>1){ $file_parts = explode('.',$value); $ext = strtolower(array_pop($file_parts)); if(in_array($ext,$allowed_types)){ $pic_path[]=$dir.$value; $total++; } } } // จำนวนรายการที่ต้องการแสดง แต่ละหน้า $perPage = 12; // คำนวณจำนวนหน้าทั้งหมด $num_naviPage=ceil($total/$perPage); // กำหนดจุดเริ่มต้น และสิ้นสุดของรายการแต่ละหน้าที่จะแสดง if(!isset($_GET['page'])){ $s_key=0; $e_key=$perPage; $_GET['page']=1; }else{ $s_key=($_GET['page']*$perPage)-$perPage; $e_key=$perPage*$_GET['page']; $e_key=($e_key>$total)?$total:$e_key; } /* for($i=1;$i<=$num_naviPage;$i++){ echo " || <a href="?page=".$i."">Page $i</a>"; } */ echo "<hr>"; // แสดงรายการ for($indexPicture=$s_key;$indexPicture<$e_key;$indexPicture++){ echo ' <div class="pic '.$nomargin.'" style="background:url('.$pic_path[$indexPicture].') no-repeat 50% 50%;"> '; echo ' <a href="'.$pic_path[$indexPicture].'" title="'.$title.'" target="_blank">'.$title.'</a> </div>'; } echo"<hr>"; for($i=1;$i<=$num_naviPage;$i++){ $myclass=""; if(!isset($_GET['page']) && $i==1){ $myclass="class="current_page""; } if(isset($_GET['page']) && $_GET['page']==$i){ $myclass="class="current_page""; } echo " || <a $myclass href="?page=".$i."">Page $i</a>"; }
Quote:ให้กับค่าลงใน array ก่อนน่ะครับ จากนั้นให้ใช้ function จากที่ส่งให้ก่อนหน้านี้คำควณตำแหน่งของ array ได้เลยครับ
<? $arr = list file folder; $Num_Rows = count($arr); $Per_Page = 2; // Per Page $Page = $_GET["Page"]; if(!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $Page_End = $Per_Page * $Page; IF ($Page_End > $Num_Rows) { $Page_End = $Num_Rows; } for($i=$Page_Start;$i<$Page_End;$i++) { echo $arr[$i]; } ?>
$arrFile = null; $objOpen = opendir("files/"); /*** folder ***/ while (($file = readdir($objOpen)) !== false) { if($file != "." && $file != "..") { $arrFile[] = $file; } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง