thaiall logomy background
coding : openphotodir.php.
my town
Source : Perl | PHP | ASP | JSP | HTML | HTML5 | JavaScript | Java | COBOL | C++ | MS Access | VBNet | VB | Python | โค้ดดี
File : openphotodir.php. ID : 9130
Skin : Default | Sons-of-obsidian | Sunburst | Highlighter | Full
<?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;
}
?>
จำนวน : 253 บรรทัด
าษาเฮชทีเอ็มแอล (HTML = HyperText Markup Language) คือ ภาษาคอมพิวเตอร์ที่ออกแบบมาเพื่อใช้ในการสร้างเว็บเพจที่เรียกดูผ่านทางเว็บเบราว์เซอร์ (Web Browser) เริ่มพัฒนาโดย ทิม เบอร์เนอรส์ ลี (Tim Berners Lee) ในปัจจุบัน HTML ล่าสุดคือ รุ่น 5 เป็นมาตรฐานหนึ่งของ ISO ซึ่งจัดการโดย World Wide Web Consortium (W3C) ในปัจจุบัน ทาง W3C ผลักดัน รูปแบบของ HTML แบบใหม่ ที่เรียกว่า XHTML รุ่นแรกคือ 1.0 (ม.ค.2543) ซึ่งมีโครงสร้างเป็นแบบ XML (eXtensible Markup Language)
าษาพีเอชพี (PHP Language) คือ ภาษาคอมพิวเตอร์ประเภทโอเพนท์ซอร์ท (Open Source Computer Language) สำหรับพัฒนาเว็บเพจแบบไดนามิก เมื่อเครื่องบริการได้รับคำร้องจากผู้ใช้ก็จะส่งให้กับ ตัวแปลภาษา ทำหน้าที่ประมวลผลและส่งข้อมูลกลับไปยังเครื่องของผู้ใช้ที่ร้องขอ ในรูปเอชทีเอ็มแอล ภาพ หรือแฟ้มดิจิทอลอื่นใด ลักษณะของภาษามีรากฐานคำสั่งมาจากภาษาซี เป็นภาษาที่สามารถพัฒนาให้ใช้งานแบบโต้ตอบกับผู้ใช้ได้
าษาไพทอน (Python Language) คือ ภาษาคอมพิวเตอร์ประเภทโอเพนท์ซอร์ท (Open Source Computer Language) สำหรับพัฒนาแอพพลิเคชั่นโดยไม่ยึดติดกับแพลตฟอร์ม (Platform) และใช้ในงานได้หลายประเภท ทั้งใช้ในการประมวลผลผ่านคอมมานด์ไลน์ หรือเป็นเว็บเพจแบบไดนามิก เมื่อเครื่องบริการได้รับคำร้องจากผู้ใช้ก็จะส่งให้โค้ดให้กับตัวแปลภาษา เพื่อทำหน้าที่ประมวลผลและส่งข้อมูลกลับไปยังเครื่องของผู้ใช้ที่ร้องขอ ในรูปข้อความ เอชทีเอ็มแอล ภาพ หรือแฟ้มดิจิทอลอื่นใด ลักษณะของภาษามีรากฐานคำสั่งมาจากภาษาซี เป็นภาษาที่สามารถพัฒนาให้ใช้งานแบบโต้ตอบกับผู้ใช้ได้ จุดที่แตกต่างกับภาษาอื่น คือ การรวบรวมจุดเด่นของแต่ละภาษามารวมเข้าด้วยกัน
อสคิวแอล (SQL = Structured Query Language) คือ ภาษาสอบถามข้อมูล หรือภาษาจัดการข้อมูลอย่างมีโครงสร้าง มีการพัฒนาภาษาคอมพิวเตอร์ และโปรแกรมฐานข้อมูลที่รองรับมากมาย เพราะจัดการข้อมูลได้ง่าย เช่น MySQL, MariaDB, MsSQL, PostgreSQL หรือ MS Access เป็นต้น สำหรับโปรแกรมฐานข้อมูลที่ได้รับความนิยมคือ MySQL หรือ MariaDB เป็น Open Source ที่ใช้งานได้ทั้งใน Linux และ Windows
วัสดีชาวโลก (Hello World) คือ ผลลัพธ์ครั้งแรกที่นักพัฒนาโปรแกรมนิยมเลือกใช้แสดงผลในโปรแกรมแรกที่เขียนขึ้นเพื่อทดสอบการทำงาน ข้อความนี้ทำให้นึกถึงมนุษย์ต่างดาวที่มาเยือนโลกและกล่าวกับมนุษย์เมื่อพบกันครั้งแรกในภาพยนตร์
ตัวอย่าง Hello World
ปรับปรุงโปรแกรม source.pl : 2565-07-24
rspsocial
Thaiall.com