利用PHP随机显示指定文件夹下某一图片的方法Php

印迹发布于:2019-2-24 1419

此代码会从指定的服务器文件夹随机选择一个图片进行显示,非常有用,图片格式为.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].'" />'; 
?>

相关导航:

1. PHP随机显示图片的代码(刷新变换图片) 

2. php自动读取文件夹下所有图片    

3. php遍历、读取文件夹中图片并分页显示图片的方法

4. 利用PHP随机显示指定文件夹下某一图片的方法

5. 随机显示文件夹下图片文件的方法


http://www.virplus.com/thread-137.htm
转载请注明:2019-2-24 于 VirPlus 发表

推荐阅读
最新回复 (0)

    ( 登录 ) 后,可以发表评论!

    返回