PHP Script Random Image เอาไว้ สุ่มรูปภาพจากโฟลเดอร์ครับ

วันนี้ IKStudio117 ขอแนะนำ Script ง่าย ๆ แค่ 1 ไฟล์ ก็สามารถสุ่มรูปภาพจากโฟลเดอร์มาโชว์หน้าเว็บได้แล้ว  ไม่พูดมากครับ เอา Code ไปเลยหล่ะกันครับ

PHP Script Random Image เอาไว้ สุ่มรูปภาพจากโฟลเดอร์ครับ

<?php
/*
-------------------------------------------------------------
|MD Random Image Generator                                  |
  |
|<?php include "image.php"; ?>                              |
-------------------------------------------------------------
*/
$dir=opendir("/home/you/public_html/folder/");
//This is the directory route to the folder
$directory="";
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on

$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir)
{
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s)
{
if(ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);

//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo "<br><img src=\"$directory$image[$randNum]\" $size[3]>";
?>

PHP Script Random Image เอาไว้ สุ่มรูปภาพจากโฟลเดอร์ครับ PHP Script Random Image เอาไว้ สุ่มรูปภาพจากโฟลเดอร์ครับ Reviewed by IOffer on มีนาคม 27, 2559 Rating: 5

ไม่มีความคิดเห็น:

Blogger Theme Blank Page

  <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html> <html b:version='2' class='v2' ...

ขับเคลื่อนโดย Blogger.