Show uploaded pdf files dynamically and filter by month name
Question
I want to show PDFs for a specific WordPress page that filters by (month)name. e.g: check the current month (October) and show october.pdf. All the PDF documents will upload from the admin panel and I want to show the current month PDF in a page in the front-end dynamically.
Here is the code that I tried:
<?php
//Get the full textual representation of current month in lower case
$months = strtolower (date('F'));
//Convert the current month name to PDF file location
$filename = '/wp-content/uploads/2020/10/'. $months.'.pdf';
if (file_exists($filename)) {
// Header content type
header("Content-type: application/pdf");
header("Content-Length: " . filesize($filename));
// Send the file to the browser.
readfile($filename);
} else {
// echo 'False ';
// die;
}
?>
0
4 months
0 Answers
9 views
0
Leave an answer
You must login or register to add a new answer .