-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
52 lines (38 loc) · 1.05 KB
/
Copy pathindex.php
File metadata and controls
52 lines (38 loc) · 1.05 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
// 0 = Hide error || 1 = Show error ( hopefully no one )
$ERROR = 0;
ini_set('display_errors', $ERROR);
ini_set('display_startup_errors', $ERROR);
error_reporting(E_ALL);
// This function return an array
function get_img(){
// Set the directory where the photos are
// "." same directory || "/path/to/dir" specific directory from web root
// "path/to/dir" child directory
$directory = ".";
// Set the extensions of the images
$extensions = ["png","jpg","jpeg"];
// Result array
$_array = array();
foreach($extensions as $ext){
$images = glob($directory . "/*." . $ext );
foreach($images as $image) {
array_push($_array, $image);
}
}
// Return an array of string (file name)
return $_array;
}
// This function return a string (url)
function random_img(){
// Get array of images
$randurl = get_img();
// Pick one random url form array
$random_url = array_rand($randurl,1);
// Return picked url
return $randurl[$random_url];
}
// Redirect to the random url
header("location: " . random_img() );
exit();
?>