I have a form that can search pdf files in a folder. I would want to modify my approach wherein there will be a user input of the date range from and to. Then display the pdf files based on the date range if nothing exists then will just simply display "Nothing Found"
I'm not really a PHP expert and I just google to come up with my current code.
$dir = './';
$exclude = array('.','..','.htaccess');
$q = (isset($_GET['q']))? strtolower($_GET['q']) : '';
//$date_from = date_create_from_format('Y-m-d',$_GET['dfr']);
//$date_to = date_create_from_format('Y-m-d',$_GET['dto']);
$res = opendir($dir);
echo '<pre>';
echo '<span style="font-weight:bold;font-size:1.5em;line-height: 40px;">Invoice Number</span> <span style="margin-left: 80px;font-size: 1.5em;font-weight: bold;">Date</span> <span style="margin-left: 105px;font-size: 1.5em;font-weight: bold;">Click to View</span> <span style="margin-left: 60px;font-size: 1.5em;font-weight: bold;">Download PDF</span><br>';
while(false !== ($file = readdir($res))) {
if(strpos(strtolower($file),$q)!== false && !in_array($file,$exclude)) {
$fileDate = date("Y-m-d", filectime($file));
echo "<span style='line-height:20px;font-size:15px;'>$file</span> <span style='margin-left:30px;font-size:15px;'>$fileDate</span> <span style='margin-left:90px;font-size:15px;'><a href='$dir$file'>View</a> </span> <span style='margin-left:130px;font-size:15px;'><a href='pdf_server.php?file=$file'>Download</a> </span> ";
echo "<br>";
}
}
echo '</pre>';
closedir($res);
And this is the form code in my main.html
<form id="tfnewsearch" method="get" action="search.php">
<label>Search for Invoice: </label><input type="text" id="tfq2b" class="tftextinput2" name="q" size="25" maxlength="120" value="JobNumber-InvoiceNumber"><input type="submit" value=">" class="tfbutton2">
</form>
<form id="tfnewsearch" method="get" action="search.php">
<!-- DATE -->
<label>Date From: </label><input type="date" id="tfq3b" class="tftextinput3" name="dfr" size="14" maxlength="120" value="Date From">
<label> and Date to: </label>
<input type="date" id="tfq4b" class="tftextinput4" name="dto" size="14" maxlength="120" value="Date To"><input type="submit" value=">" class="tfbutton4">
</form>