Looking for the misty rain and the world of mortals, and thinking about poetry and painting in the south of the Yangtze River

Random picture API source code - PHP calls all subdirectory pictures randomly

Wandering the Jianghu 2017-08-11 Browse (17280) Comments (7)
  1. I have nothing to do. I saw a lot of people doing random picture APIs. They are very handsome and very forced

  2. use Baidu Search php Code, I haven't learned php Any code, such as Xiaobai, is simply and rudely replaced by a line of code according to the gourd painting ladle. I don't know if there is a problem with the wood.

 Random picture API source code - PHP calls all subdirectory pictures randomly


Description here:

  • This code is very cool. You can use wildcards to represent the path. It's very small. I like it

  • My picture home directory is images , the specific image file is placed in images Multiple subdirectories under the directory, so write as follows

  • establish img. php , write the following code, and then reference img. php Web address

This is found by Baidu, and only the fixed php route:

 <? php   //Get the image array in the folder $img_array = glob("./images/*/*.{gif,jpg,png}",GLOB_BRACE);  //Select a random picture from the array $img = array_rand($img_array);   //Show pictures on the page echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />';   ?


This is my correction. It directly displays the random image path

 <? php //This will get an array of all gif, jpg and png images in a folder $img_array = glob("./images/*/*.{gif,jpg,png}",GLOB_BRACE); //Select a random picture from the array $img = array_rand($img_array); //Show pictures on the page header("location:.$img_array[$img]");    ?>
Title: Random Picture API Source code - PHP Call all subdirectory pictures randomly
Author authorization: Unless otherwise specified, this document is written by Intoxicated with Chinese style Original compilation and authorization Intoxicated with Chinese style blog Publication.
Copyright notice: This article does not use any agreement authorization, and you can freely reprint or use it in any form.
label:
Comment List (7) Comments
 Netizen nickname: 110
one hundred and ten tourist 2021-03-03 reply
I step on it! I step, step, step! I support! I top, top, top! Young man, it's very good. It's written very well!
 Netizen nickname: visitor
visitor tourist 2019-10-14 reply
Why do I test locally only in a random folder..
 Netizen nickname: Jiang Chen
Jiang Chen tourist 2017-08-11 reply
Worship
 Netizen nickname: Intoxicated with Chinese style
Intoxicated with Chinese style administrators 2017-08-11 reply
@Intoxicated with Chinese style Kill me too
 Netizen nickname: Jiang Chen
Jiang Chen tourist 2017-08-12 reply
@Jiang Chen No, no, no, God~
 Netizen nickname: Dwight
Dwight tourist 2017-08-11 reply
Ha ha, the api is really angry
 Netizen nickname: Intoxicated with Chinese style
Intoxicated with Chinese style administrators 2017-08-11 reply
@Intoxicated with Chinese style I don't deserve it. You are very angry upstairs

Comment