Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // "LatestNewsletter.php"
- // Within the folder media/news, there are sub-folders for each volume (year) of newsletter
- // These are named V1, V2, V3 etc.
- // Within each Volume folder, there are newsletters named VnNn.pdf, e.g, V3N1.pdf, V3N2.pdf etc. for volume 3
- // This code finds the most recent newsletter for the current year, given that Volume 1 was year 2020
- // Determine the current year
- $currentYear = date('Y');
- // Determine the volume based on the current year
- $volume = 'V' . ($currentYear - 2019); // Assuming volume 1 corresponds to year 2020
- // Set the base directory where newsletters for the current year are stored
- $newsletterDirectory = 'media/news/' . $volume . "/";
- // Initialize variables to keep track of the latest newsletter found
- $latestNewsletter = '';
- $newsletterNumber = 1;
- // Loop through each newsletter for the current volume until it fails to find one
- while (file_exists($newsletterDirectory . $volume . 'N' . $newsletterNumber . '.pdf')) {
- $latestNewsletter = $volume . 'N' . $newsletterNumber . '.pdf';
- $newsletterNumber++;
- }
- // If no newsletters were found, send an error message
- if (empty($latestNewsletter)) {
- echo 'No newsletters found for volume ' . $volume . '. ' . $newsletterDirectory . " " . $newsletterNumber;
- } else {
- // Generate the link to the latest newsletter
- $latestNewsletterLink = $newsletterDirectory . $latestNewsletter;
- // Send the link to the front-end code
- echo $latestNewsletterLink;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment