peter-cooper
asked on
List files in folder sub-directories
I have a script that when clients create a pdf file, it is placed in a folder named with there own code. This is in a main folder called 'destcerts' and the folder structure ends up looking like the illustration below. What I need to do as admin is have access to these files and the only way I can do that at the moment is to hard code the sub-directory in the code and that is not practical for obvious reasons.
What I thought I could do is, have a select dropdown with a list of clients which when selected could trigger perhaps a change event which would say loop for the chosen client and display the files. Unfortunately, my php or jquery is not good enough to achieve this and I would be grateful if someone could show me the way to g forward with this. Many thanks
What I thought I could do is, have a select dropdown with a list of clients which when selected could trigger perhaps a change event which would say loop for the chosen client and display the files. Unfortunately, my php or jquery is not good enough to achieve this and I would be grateful if someone could show me the way to g forward with this. Many thanks
<div id="viewCerts" style="display:none;">
<?php
$sub = 'destcerts/';
// READ THE NAMES OF FILES IN THE SUB-DIRECTORY
$fff = new DirectoryIterator($sub);
$sss = array();
foreach ($fff as $filedata)
{
// SKIP THE "DOT" FILES
if ($filedata->isDot()) continue;
// ACTIVATE THIS LINE TO RESTRICT IT TO PDF FILES ONLY
if ($filedata->getExtension() != 'pdf') continue;
// SET AN INDICATOR TO SHOW WE FOUND DATA
// CREATE LINKS TO THESE FILES
$nom = $filedata->getFilename();
//$value = substr ($nom, 0, 4);
$_SESSION['value'] = $nom;
//if($value == 'DEMO') {
$lnk
= '<img src="destcerts/PDF_icon_100.png" style="margin-bottom: 15px; margin-top:15px;"><br /><a href="'
. $sub
. '/'
. $nom
. '" style="color:#0099FF; text-decoration:none; font-size:12px; font-family: Verdana, Geneva, sans-serif;">'
. $nom
. '</a>'
;
//}
// COLLECT THE LINKS HERE
$sss[] = $lnk;
}
// ACCUMULATE THE TABLE ROWS HERE
$trs = NULL;
// COLLECT GROUPS OF FOUR
If(!empty($sss)){
while (!empty($sss))
{
$td1 = array_shift($sss) or NULL;
$td2 = array_shift($sss) or NULL;
$td3 = array_shift($sss) or NULL;
$td4 = array_shift($sss) or NULL;
// USE HEREDOC TO INSERT THESE INTO A TABLE ROW
$tr = <<<EOD
<tr>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td1</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td2</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td3</td>
<td align="center" width="20%" style="padding-bottom:20px !important;">$td4</td>
</tr>
EOD;
// APPEND THE TABLE ROW TO THE OTHER ROWS
$trs .= $tr;
}
}
else{
$msg = "There are no files to display";
$tr = <<<EOD
<tr>
<td style="text-align:center; padding: 10px !important; font-weight: normal;">$msg</td>
</tr>
EOD;
$trs .= $tr;
}
// USE HEREDOC TO INSERT THE TABLE ROWS INTO THE TABLE
$tab = <<<EOD
<table id="pdfDownload" width="97%" align="center" border="1" cellspacing="10" cellpadding="0" style="border:1px solid grey; padding-bottom: 10px; margin-bottom:20px;">
<th style="text-align:center; padding: 10px !important; padding-bottom: 20px; border:1px solid black; background-color: #3399FF; color: white; font-size: 18px !important;" colspan="4">Destruction Certificates Download</th>
<tr>
<th></th>
</tr>
$trs
</table>
EOD;
// SHOW THE WORK PRODUCT
echo $tab;
?>
</div>
.
..
destcerts
client1
client2
client3
etc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much dave.
You're welcome, glad to help.
If you have the time and interest and want to learn enough PHP to become a developer yourself, this article can help you get started.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
Best of luck with it, ~Ray