-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.php
32 lines (26 loc) · 879 Bytes
/
cron.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
// get images and leave everything else alone
function getImagesFromDir($path) {
$images = array();
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// checks for gif, jpg, png
if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) {
$images[] = $img_file;
}
}
closedir($img_dir);
}
return $images;
}
// pick random image
function getRandomFromArray($array) {
$num = array_rand($array);
return $array[$num];
}
$path = "***PATH_TO_IMAGES***";
$imgList = getImagesFromDir($path);
$img = getRandomFromArray($imgList);
// generate .htaccess
$htaccess = "Options +FollowSymLinks\n\nRewriteEngine on\n\nRewriteRule ^background\.jpg$ http://%{HTTP_HOST}/$path/$img [L]\n\n";
file_put_contents($path.'/.htaccess', $htaccess);