File : openphotodir.php. ID : 9130
Skin : Default | Sons-of-obsidian | Sunburst | Highlighter | Frame
<?php
/* openphotodir.php
source from http://www.thaiall.com/perlphpasp/source.pl?9130
# Version 5 (2563-10-26)
- รองรับ code บรรทัดเดียว
- เพิ่ม kanit google font
- ใช้ .imgborder แบบ /actress/joom.htm
- ปรับ tab
# Version 4 (2561-11-29)
- เปลี่ยน lightbox จาก 2.04 เป็น 2.10.0 เรียกจาก cdnjs
# Version 3 (2558-05-20)
- 2558-05-20 สำหรับ xampp 3.0.12 : php 5.4.4 บน mculampang.com, watermark changed
# Version 2 (2555-09-09)
- 2555-09-09  เรียงแฟ้มใหม่ และใส่คำอธิบายเตรียมสอน source code และผ่าน xhtml แล้ว
- 2555-08-15  เพิ่ม doc docx ใน $allow_ext เพื่อใช้ใน /tqf/cpsc
# Version 1 (2555-04-11)
- รุ่นล่าสุดใช้งานที่ http://www.thaiall.com/handbill/openphotodir.php
-  เพิ่ม pptx  ใน $allow_ext  เพื่อใช้ใน /pptx
- .htaccess  # AddType application/vnd.openxmlformats .docx .pptx .xlsx .doc .xls .ppt
- index.php # header("Location: http://www.thaiall.com/handbill/openphotodir.php?folder=../pptx/"); 
*/
if ($_SERVER["SERVER_NAME"] == "www.thaiall.com") { session_save_path("/home/users/web/b352/hy.thaiwebsearch/cgi-bin/tmp"); }
/* 1 : declaration */
session_start();
ini_set('arg_separator.output', '&amp;');
ini_set('memory_limit', '80M');
$version = 'OpenPhotoDir version 5.2563-10-26';
$title = 'ODS : Open Directory System';
$keyword ='open,photo,gallery,directory';
$description ='open directory system is used to list the photos and files';
$type = 'list'; /* t1 = list, t2, t3, t4, t5, t6 */
$h = ' height:100px;'; 
$w = ' width:100px;';
$hb = 'background-color:teal;color:#ccffff;text-align:center;';
$hb_main = 'background-color:#ddddff;';
$hb_top = 'background-color:white;';
$b = 'background-color:#666644;';
$filename_bg1 = 'background-color:#f9f9f9;';
$filename_bg2 = 'background-color:#dddddd;';
$colortext = 'black';
$tot = 200;
$max_size = 1000000; /* 1 MB = 1,000,000 */
$file_skiped = array("ta1.gif","ta2.gif","ta3.gif","openphotodir.gif","agenda_clip_1hr.jpg");
$watermark = "openphotodir.gif";
$footer = ""; /* ค่าปริยาย คือ footer ของ thaiall.com */
/* 2 : set variables */
if (isset($_GET['folder']))  $_SESSION["folder"] = $_GET['folder']; 
if (isset($_SESSION['folder']))  $myfolder = $_SESSION["folder"]; else $myfolder = "./";
$allow_ext = array("jpg", "gif", "png", "mht","pptx","xlsx","docx","ppt","xls","doc");
if (isset($_GET['type']))  { $type =$_GET['type']; $allow_ext = array("jpg", "gif", "png"); }
if (isset($_GET['imgh']))  $h = " height:".$_GET['imgh'];
if (isset($_GET['imgw']))   $w = " width:".$_GET['imgw'];	
if (isset($_GET['start']))   $start = $_GET['start']; else $start = 1;
if (!isset($_GET['imgh']) && !isset($_GET['imgw'])) {
  if (strlen($h) < 2) $h = ' height:120px'; 
  if (strlen($w) < 2) $w = ' width:120px';	
}
if (isset($_GET['bgcolor'])) $b = "background-color:".$_GET['bgcolor'];	
if (isset($_GET['tot'])) $tot = $_GET['tot'];	
if (isset($_GET['f']))  img_enlarge(base64_decode($_GET['f']),$myfolder);
/* 3 : body starting */
?><!DOCTYPE html><html lang='th'><head><title><?php echo $title;?></title><meta charset='windows-874' />
<meta name='keywords' content='<?php echo $keyword; ?>' />
<meta name='description' content='<?php echo $description; ?>' />
<meta property='og:image' content='http://www.thaiall.com/handbill/lightbox.jpg' />
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Kanit' />
<style>
body{color:<?php echo $colortext;?>;<?php echo $b;?>;font-family:kanit;text-align:center;font-size:10px;margin-top:0;margin-left:0;}
a:link{color:#0000aa;text-decoration:none;}
a:visited{color:red;text-decoration:none;}
a:hover{color:blue;text-decoration:underline overline;}
img{border:0;}
td{font-size:10pt;text-align:left;color:<?php echo $colortext;?>;}
.tb_main{width:100%;height:80px;border:1px;<?php echo $hb_main;?>}
.tb_top{height:80px;<?php echo $hb_top;?>}
.tb_page{height:30px;background-color:black;}
.imgborder {border:5px outset white;border-radius:20px;box-shadow:5px 5px 5px gray;} 
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/css/lightbox.css" type="text/css" media="screen" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.10.0/js/lightbox-plus-jquery.js"></script>
</head><body>
<?php 
/* 4 : main menu */ 
?>
<table class="tb_main">
<tr class="tb_top"><td style="text-align:center;"><?php echo $title;?></td>
<td style='text-align:right;'><b>Style : </b>
<?php echo '<a href="?">list</a> | '; ?>
<?php if (!isset($_SESSION["folder"]) || strtolower(substr($_SESSION["folder"],0,6)) != '../mht') { ?>
<?php if (isset($_GET["type"]) && $_GET["type"]=="t2") echo 'hight 100 | '; else echo "<a href='?type=t2&amp;imgh=80&amp;tot=9&amp;'>height 100</a> | "; ?>
<?php if (isset($_GET["type"]) && $_GET["type"]=="t3") echo 'width 200 | '; else echo "<a href='?type=t3&amp;imgw=200&amp;tot=8&amp;'>width 200</a> | "; ?>
<?php if (isset($_GET["type"]) && $_GET["type"]=="t4") echo 'bg-yellow | '; else echo "<a href='?type=t4&amp;bgcolor=yellow&amp;tot=18&amp;'>bg-yellow</a> | "; ?>
<?php if (isset($_GET["type"]) && $_GET["type"]=="t5") echo 'bg-gray | '; else echo "<a href='?type=t5&amp;bgcolor=gray&amp;tot=9&amp;'>bg-gray</a> | "; ?>
<?php if (isset($_GET["type"]) && $_GET["type"]=="t6") echo 'frame'; else echo "<a href='?type=t6&amp;size=original&amp;tot=9&amp;'>frame</a>"; ?>
<?php } ?>
</td></tr></table>
<?php
/* 5 : file listing */ 
if ($type == "list") 
  echo "<table style='width:100%' border='1' cellspacing='0' cellpadding='3' ><tr style='".  $hb ."'><td style='width:40px;text-align:center;color:white;'>ลำดับ</td><td style='text-align:center;color:white;'>ชื่อแฟ้ม</td><td style='width:120px;text-align:center;color:white;'>ขนาด  (bytes)</td><td style='width:120px;text-align:center;color:white;'>วันที่</td></tr>"; 
else 
  echo "<table><tr><td>";
$i = 0;
$files = array();
$d = opendir($myfolder); /* กำหนดการเชื่อมโยงของ directory */
while ($file = readdir($d)) { /* อ่านชื่อแฟ้มใน directory */
  $files[$file] = $file; 
}
asort($files); /* Sort an array and maintain index association */
$files=array_keys($files);
foreach($files as $k => $list) {
/* before sort while ($list = readdir($d)) */
  $elist = base64_encode($list);
  if (in_array(strtolower(substr($list,-3)), $allow_ext) || in_array(strtolower(substr($list,-4)), $allow_ext)) {
    if (!in_array($list, $file_skiped)) {
      $i = $i + 1;
      if ($type == "list") {
        if ($i % 2 ==0) $bg = $filename_bg1; else $bg = $filename_bg2;
        if (strtolower(substr($list,-3)) == "mht" || strtolower(substr($list,-4)) == "pptx")
          echo "<tr style='$bg'><td style='text-align:center;'>$i</td><td><a href='". $_SESSION["folder"] ."$list'>$list</a></td><td style='text-align:right;'> ". number_format(filesize($myfolder . $list)) ."</td><td>".  date("M d Y H:i", filemtime($myfolder . $list)) .  "</td></tr>";
        else
          echo "<tr style='$bg'><td style='text-align:center;'>$i</td><td><a href='?enl=y&amp;f=$elist'  rel='lightbox[ods]'>$list</a></td><td style='text-align:right;'> ". number_format(filesize($myfolder . $list)) ."</td><td>".  date("M d Y H:i", filemtime($myfolder . $list)) .  "</td></tr>";
      } else {
        if ($tot > 500) exit;
        $first = (($start * $tot) - ($tot - 1)); 
        $last = ($start * $tot);
        if ($i >= $first && $i <= $last) {
          echo "<a href='?enl=y&amp;f=$elist' rel='lightbox[ods]' ";
          if ($type == "t6") echo " target='f'";
          echo "><img class='imgborder' src='?f=$elist' ";
          if ($type == "t3") $h ="";
          if ($type != "t6") echo " style='$w" . "px;$h;'";
          echo " alt='$i' /></a>\n";
        }
      }
    }
  }
}
if ($type == "list") echo "</table>"; else echo "</td></tr></table>";
$tpage = round(($i / $tot) + 0.499);
/* 6 : total files & page selction */ 
?>
<table style='width:100%;' class='tb_page' cellspacing='0' border='0'>
<tr><td style='background-color:#dddddd;width:100px'>จำนวน <?php echo $i;?> ภาพ</td>
<?php if (isset($_GET["type"])) {?>
<td style="background-color:white">หน้าที่ : <b><?php 
$q = explode("&start",$_SERVER["QUERY_STRING"]);
for ($j=1;$j<=$tpage;$j++) {
  if (isset($_GET["start"]) && $j == $_GET["start"]) echo "_[ $j ]_"; else echo "<a href='?". str_replace("&","&amp;",$q[0]) ."&amp;start=$j'>_". $j. "_</a>";
}
echo '</b></td>';
}
echo "</tr></table>";
if ($type=="t6") echo "<iframe src='http://www.thaiall.com/handbill/imdb.jpg' style='width:100%;height:600px;' name='f'></iframe>"; ?>
<?php
/* 7 : footer */ 
if (strlen($footer) > 5) { echo $footer; } else {
?>
<div style='text-align:center;'>
<script><!--
google_ad_client = "ca-pub-3309619467978767";
/* 23 handbill 15 */
google_ad_slot = "0370469210";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<br/>
<?php echo $version;?> ( Validator : <a href="https://validator.w3.org/nu/?doc=http%3A%2F%2Fwww.thaiall.com%2Fhandbill%2Fopenphotodir.php">xhtml</a>)
<a href="http://www.thaiall.com/handbill/openphotodir.php?folder=../handbill/">/handbill</a>
:: <a href="http://www.thaiall.com/perlphpasp/source.pl?9130">source code</a>
:: <a href="http://www.facebook.com/thaiall">http://www.facebook.com/thaiall</a> 
:: <a href="http://www.twitter.com/thaiabc">@thaiabc</a> 
</div>
<?php
}
echo "</body></html>";
/* 8 : image enlarge (ทำงานใน preview mode แต่ไม่ทำงานใน listing mode) */ 
function img_enlarge($f,$myfolder) {
global $max_size,$watermark;
if(isset($_GET['enl'])) {
if (filesize($myfolder . $f) > $max_size && $_SERVER["SERVER_NAME"] == 'www.thaiall.com' && (!isset($_GET["pass"]) ||  $_GET["pass"] != "ไทย")) {
echo "<html><head><meta http-equiv=content-type content='text/html; charset=windows-874'></head><body>
<form action=? method=get><input type=hidden name=f value=". $_GET['f']. "><input type=hidden name=enl value=y>
<input name=pass><input type=submit><br/>คำว่า thai สะกดเป็นภาษาไทยว่าอย่างไร<br/>กรอกในช่องว่าเพื่อตรวจสอบก่อนดูภาพขนาดใหญ่</form>";
exit;
}
list($width, $height, $image_type) = getimagesize($myfolder . $f);
switch ($image_type) {
case 1: $dest = imagecreatefromgif($myfolder . $f); break;
case 2: $dest = imagecreatefromjpeg($myfolder . $f); break; 
case 3: $dest = imagecreatefrompng($myfolder . $f); break;
default: return '';  break;
}
if (file_exists($watermark)) {
  $src = imagecreatefromgif($watermark); /* ใส่ watermark เข้าไปในภาพ */
  $bg_color = imagecolorat($src, 1, 1);
  imagecolortransparent($src, $bg_color);
  imagecopymerge($dest, $src, 1, 1, 1, 1, 300, 50, 70); /* (dest, src, dest_x, dest_y , src_x, src_y, src_w, src_h, 0to100) */
}
switch ($image_type) {
case 1: header('Content-Type: image/gif'); imagegif($dest); break;
case 2: header('Content-Type: image/jpeg'); imagejpeg($dest); break;
case 3: header('Content-Type: image/png'); imagepng($dest); break;
}
imagedestroy($dest);
imagedestroy($src);
} else {
header('Content-Type: image/jpeg');
imagejpeg(img_thumb($f,$myfolder));
}
exit;
}
/* 9 : thumbnail (ทำงานใน preview mode แต่ไม่ทำงานใน listing mode) */ 
function img_thumb($f,$myfolder) {
global $h,$w;
$mh = explode(":",$h);
$mw = explode(":",$w);
$max_width = $mh[1];
$max_height = $mw[1];
$source_pic = $f;
list($width, $height, $image_type) = getimagesize($myfolder . $f);
switch ($image_type) {
case 1: $src = imagecreatefromgif($myfolder. $f); break;
case 2: $src = imagecreatefromjpeg($myfolder. $f);  break;
case 3: $src = imagecreatefrompng($myfolder. $f); break;
default: return '';  break;
}
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) ){
$tn_width = $width;
$tn_height = $height;
}elseif (($x_ratio * $height) < $max_height){
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}else{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$tmp = imagecreatetruecolor($tn_width,$tn_height);
if(($image_type == 1) || ($image_type==3)) {
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $tn_width, $tn_height, $transparent);
}
imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
$final_image =$tmp;
return $final_image;
}
?>