I have been playing with this for awhile and just can't seem to do exactly what I want, though maybe someone could give me a little perspective as I'm probably too zoomed in.
Basically, I have a snippet which opens a directory and lists all the files, I use the string from the name of the file (e.g. newsletter10012009.pdf > which becomes > newsletter10012009 to also get an accurate date for which the file (newsletter) was for, this is saved in a variable zdate. In another location on the site I want to open this directory and show only 1 file the closest string date - (not upload) to today. I'm just wondering the most efficient way to adapt this so....only november shows until december is uploaded.
please see the code below...
Code: Select all
function makedate($date){
global $month, $day, $year;
$day = date("d");
$month = date("m");
$year = date("Y");
}
// Load up an array with the directory listing:
$dir = '/faithchurch/assets/files/Bulletin/';
echo '<ul>';
if ($handle = @opendir($dir)) {
while (false!== ($filename = readdir($handle))) {
$files[] = $filename;
}
closedir($handle);
natcasesort($files);
$files = array_reverse($files);
// Process the files from the directory listing;
// but skip any files beginning with dots (.):
foreach ($files as $filename) {
if (is_file($dir.$filename)) {
$filetxt = substr($filename, 0, strrpos($filename, '.'));
$month = substr($filetxt, 9, 2);
$day = substr($filetxt, 11, 2);
$year = substr($filetxt, 13, 4);
$zdate = date("F j Y", mktime(0, 0, 0, $month, $day, $year));
echo '<li><a href="assets/files/Bulletin/'.$filename.'" target="_blank">'.$zdate.'</a></li>';
}
}
}
echo '</ul>';
all the documents in from today - backward
Thanks for any suggestions.