-
Notifications
You must be signed in to change notification settings - Fork 2
/
image.php
32 lines (23 loc) · 854 Bytes
/
image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
$dir = 'images';
// Initiate array which will contain the image name
$imgs_arr = array();
// Check if image directory exists
if (file_exists($dir) && is_dir($dir) ) {
// Get files from the directory
$dir_arr = scandir($dir);
$arr_files = array_diff($dir_arr, array('.','..') );
foreach ($arr_files as $file) {
//Get the file path
$file_path = $dir."/".$file;
// Get extension
$ext = pathinfo($file_path, PATHINFO_EXTENSION);
if ($ext=="jpg" || $ext=="png" || $ext=="JPG" || $ext=="PNG" || $ext=="jpeg" || $ext=="JPEG") {
array_push($imgs_arr, $file);
}
}
$count_img_index = count($imgs_arr) - 1;
$random_img = $imgs_arr[rand( 0, $count_img_index )];
}
?>
<img height="95%" src="<?php echo $dir."/".$random_img ?>">