Home >Backend Development >PHP Tutorial >How to randomly display images in a specified folder in php, _PHP tutorial

How to randomly display images in a specified folder in php, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:46:331151browse

How to randomly display images in a specified folder in php.

This article describes an example of how to randomly display images in a specified folder in php. Share it with everyone for your reference. The details are as follows:

This code will randomly select an image from the specified server folder to display, which is very useful. The image format is .gif, .jpg, .png

<&#63;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].'" />'; 
&#63;>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1031484.htmlTechArticleHow to randomly display images in a specified folder in php. This article describes how to randomly display images in a specified folder in php. method. Share it with everyone for your reference. The details are as follows: This code...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn