ถ้า php ก็นี่ครับ
Category : Php Scripts
โปรแกรม สุ่มรูปภาพ
เขียนโดย กอล์ฟ , 09-07-2002
มาแสดงที่หน้าเวปไซต์ของคุณใช้งานง่ายจริง ๆครับ
Source Code
<?php
// print a random image. Don't forget ending slash!
// setting $type to 'all' will return all images.
print getRandomImage('images/'); // ให้แก้ตรงนี้เป็น directory ที่คุณเก็บภาพที่ต้องการให้ random
function getRandomImage($dir,$type='random')
{
global $errors,$seed;
if (is_dir($dir)) {
$fd = opendir($dir);
$images = array();
while (($part = @readdir($fd)) == true) {
if ( eregi("(gifjpgpngjpeg)$",$part) ) {
$images[] = $part;
}
}
// adding this in case you want to return the image array
if ($type == 'all') return $images;
if ($seed !== true) {
mt_srand ((double) microtime() * 1000000);
$seed = true;
}
$key = mt_rand (0,sizeof($images)-1);
return "<img src='".$dir . $images[$key]."'>";
} else {
$errors[] = $dir.' is not a directory';
return false;
}
}
?>
เท่านี้ก็เป็นอันเสร็จเรียบร้อยแล้วครับ เวลาเรียกใช้งานก็ให้เรียกผ่าน Tag
<?include("/path/to/random.php");?>
ต้องขอบคุณ คุณกอล์ฟ มา ณ ที่นี้ด้วย สำหรับสคริปตัวนี้