
November 30th, 2012, 12:04 PM
|
|
Me
|
|
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,263
 
Time spent in forums: 2 Weeks 1 Day 5 h 48 m 41 sec
Reputation Power: 9
|
|
First, your date matching is incorrect. You will have better luck using timestamps and time()/ strtotime().
You can do something like:
PHP Code:
//get a timestamp for the start of each season
$spring = strtotime('23 march');
$summer = strtotime('21 june');
$autumn = strtotime('23 september');
$winter = strtotime('21 december');
//get the current timestamp
$current = time();
//then check each season in reverse order
//if past winter start
if($current >= $winter){
$season = "winter";
//if past autumn start
} elseif($current >= $autumn){
$season = "autumn";
//if past summer start
} elseif($current >= $summer){
$season = "summer";
//if past spring start
} elseif($current >= $spring){
$season = "spring";
//if before spring start, must be previous year winter still
} else {
$season = "winter";
}
As for the reading a random file, what you have might work (I didn't test it, it looks ok) but there are better functions that are easier to work with such as glob().
PHP Code:
//get the full folder using the season var set above
$folder = "./images/personal/headers/{$season}/";
//get an array of files matching the extensions jpg,jpeg,png,gif in that folder
$files = glob("{$folder}*.{jpg,jpeg,png,gif}", GLOB_BRACE);
//get a random key from the array
$rand = array_rand($files);
//get the filename from the list of files
$filename = $files[$rand];
//get the extension to determine header
$ext = substr($filename, strrpos($filename,'.'));
//send out correct header based on ext
header("Content-Type: image/{$ext}");
//output the file
readfile($filename);
I also changed the header redirect that you were doing with what I feel is better which is to just output the header and read the file.
|