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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 09:46:33
Original
1190 people have browsed it

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;>

Copy after login

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...
Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template