Select Page

Random Image Script

Written by Chang

我是 jacky,喜歡 X 檔案,喜歡科幻電影,喜歡旅遊,哪裡都好 但是超愛台灣。

2004-10-31

影像隨機展示:

隨機影像展示


影像隨機展示的語法:
<img src=”/dropbox/2003/rotate/rotate.php” alt=”A Random Image” />

另外再建立一隨機展示的PHP檔,CODE如下:

<?php
/*
By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
http://photomatt.net/scripts/randomimage
*/

// Make this the relative path to the images, like “../img” or “random/images/”.
// If the images are in the same directory, leave it blank.
$folder = ”;

// Space seperated list of extensions, you probably won’t have to change this.
$exts = ‘jpg jpeg png gif’;

$files = array(); $i = -1; // Initialize some variables
if (” == $folder) $folder = ‘./’;
$handle = opendir($folder);
$exts = explode(‘ ‘, $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match(‘/.’.$ext.’$/i’, $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it’s good
++$i;
}
}
}
closedir($handle); // We’re not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header(‘Location: ‘.$folder.$files[$rand]); // Voila!
?>

語法資料來源為Photo Matt

You May Also Like…

芮氏規模 6.0

芮氏規模 6.0

昨(6)日深夜在花蓮發生芮氏規模6.0,震度7級的有感地震,造成多處災情。 20180206-2350 花蓮縣政府北偏東方 18.3...

WordPress 4.9

WordPress 4.9

網站建置順利後,現在版本升級越來越容易了。   https://wordpress.org/news/2017/11/tipton/

改版文

改版文

停了很長一段時間沒有維護的網站,這幾天進行維護與佈景主題式樣修改。新增一些程式碼做為網站頁面呈現的測試,持續改造往簡單設計邁進。...

0 Comments