<?php function read_dir($dir, $array = array()){ $dh = opendir($dir); $files = array(); while(($file = readdir($dh)) !== false) { $flag = false; if($file !== '.' && $file !== '..' && !in_array($file, $array)) { $files[] = $file; } } return $files; } $path = 'photo_mini/'; $folder = read_dir($path); foreach($folder as $value){ echo '<img src="'.$path.$value.'" />'; } ?>
เพิ่ม light box
<!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=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/jquery.lightbox-0.4.js"></script> <script type="text/javascript"> $(function(){ $('#gallery a').lightBox(); }); </script> </head> <body> <div id="gallery"> <?php function read_dir($dir, $array = array()){ $dh = opendir($dir); $files = array(); while(($file = readdir($dh)) !== false) { $flag = false; if($file !== '.' && $file !== '..' && !in_array($file, $array)) { $files[] = $file; } } return $files; } $path = 'photo_small/'; $folder = read_dir($path); foreach($folder as $value){ echo '<a href="photo_big/'.$value.'"><img src="'.$path.$value.'" /></a>'; } ?> </div> </body> </html>
อันนี้ เป็นการอ่านรูปผ่าน php ล้วนๆ ครับ แก้ $host กับ $path ก็เสร็จแล้ว ไม่ต้องทำรูปเล็กด้วย
<!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=utf-8" /> <title>Untitled Document</title> </head> <body> <div id="gallery"> <?php function read_dir($dir, $array = array()){ $dh = opendir($dir); $files = array(); $i = 0; while(($file = readdir($dh)) !== false) { if($file !== '.' && $file !== '..' && !in_array($file, $array)) { $files[$i] = $file; $i++; } } return $files; } $host = 'http://www .ชื่อเว็บ.com/ไฟล์.php'; $path = 'photo/'; $folder = read_dir($path); if($folder[$_GET['id']]){ echo '<img src="'.$path.$folder[$_GET['id']].'" />'; }else{ echo '<img src="'.$path.$folder[0].'" />'; } ?> </div> <?php if($_GET['id'] != 0){ ?> <a href="<?php echo $host.'?id='.($_GET['id']-1); ?>"><- Back</a> <?php } if((count($folder)-1) > $_GET['id']){ ?> <a href="<?php echo $host.'?id='.($_GET['id']+1); ?>">Next -></a> <?php } ?> </body> </html>