Search the Community
Showing results for tags 'dates images rotate'.
-
hi im trying to create a script that swaps image folders depending on the season. This can be used for website headers or adverts so during easter for instance you could swap to a theme for your header image without manually doing it. when the folder is chossen the script randomly chooses an image form the folder. Its not working however hense this post, anyone with even a small amount of php knowlege will probably spot the problem straight away. Please could you help me get this working. I call it using a css style background: #0c1a3e URL(../rotate.php) no-repeat center center ; Thanks <?php // 23march to20june spring if ((date('m') == 03) && (date('d') >= 23) || (date('m') == 06) && (date('d') <= 20)) { $folder = './images/personal/headers/spring/'; } // 21june 22sept summer else if ((date('m') == 06) && (date('d') >= 21) || (date('m') == 09) && (date('d') <= 22)) { $folder = './images/personal/headers/summer/'; } // 23 sept to dec 20 autumn else if ((date('m') == 09) && (date('d') >= 23) || (date('m') == 12) && (date('d') <= 20)) { $folder = './images/personal/headers/autumn/'; } // 21 dec to 22 march winter else ((date('m') == 12) && (date('d') >= 21) || (date('m') == 03) && (date('d') <= 22)) { $folder = './images/personal/headers/winter/'; } //otherwise // else { $folder = './images/personal/headers/'; } // Space seperated list of extensions, you probably won't have to change this. $exts = 'jpg jpeg png gif'; $files = array(); $i = -1; // Initialize some variables if ('' == $folder) $folder = './'; $handle = opendir($folder); $exts = explode(' ', $exts); while (false !== ($file = readdir($handle))) { foreach($exts as $ext) { // for each extension check the extension if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive $files[] = $file; // it's good ++$i; } } } closedir($handle); // We're not using it anymore mt_srand((double)microtime()*1000000); // seed for PHP < 4.2 $rand = mt_rand(0, $i); // $i was incremented as we went along header('Location: '.$folder.$files[$rand]); // Voila! ?>