php隨機顯示指定文件夾下圖片的方法
更新時間:2015年07月13日 15:58:20 作者:不吃皮蛋
這篇文章主要介紹了php隨機顯示指定文件夾下圖片的方法,涉及array_rand隨機數組操作的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php隨機顯示指定文件夾下圖片的方法。分享給大家供大家參考。具體如下:
此代碼會從指定的服務器文件夾隨機選擇一個圖片進行顯示,非常有用,圖片格式為.gif,.jpg,.png
<?php //This will get an array of all the gif, jpg and png images in a folder $img_array = glob("/path/to/images/*.{gif,jpg,png}",GLOB_BRACE); //Pick a random image from the array $img = array_rand($img_array); //Display the image on the page echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; ?>
希望本文所述對大家的php程序設計有所幫助。
相關文章
解決PHP程序運行時:Fatal error: Maximum execution time of 30 seconds
最近做的程序中涉及到的循環(huán)比較多且處理的情況較復雜,在運行程序時出現執(zhí)行超時提示如下:Fatal error: Maximum execution time of 30 seconds exceeded in D:\php\AppServ\www\sum3\test.php on line 3通過在網上搜索,找到了解決方法和大家分享,下面來一起看看吧。2016-11-11