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

<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>

Open in new window

.
..
destcerts
  client1
  client2
  client3
  etc

Open in new window

peter-cooperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Here is a php code that will list the files in the current directory plus a list of the sub-directories.  It doesn't have a drop-down and you will probably have to make some changes for your use.  Put it in 'destcerts' and run it.
<?php
// file extensions that will be recognized
$extstr = " php html asp aspx";
$parts = array();
$listing = array();
$dirs = array();

if ($handle = opendir('.')) {
		$j = 0;
    while (false !== ($dlist[$j] = readdir($handle))) {
        //if ($file != "." && $file != "..") $j++;
        if ($dlist[$j] != "." && $dlist[$j] != "..") $j++;
				}
		//sort($dlist, SORT_STRING);
		natcasesort($dlist);
		foreach ($dlist as $key => $val) {
		$parts = explode(".",$val);
		if(isset($parts[1]) && (strpos($extstr, $parts[1]) > 0)) {
			if(!isset($parts[2])) {
    		$listing[] = $val;
				}
			}
		if(is_dir($val)) $dirs[] = $val;
		}
    closedir($handle);
		//sort($listing, SORT_STRING);
		natcasesort($listing);
		$Lencnt = count($listing);
		$clng = 27;
		$divsr = ceil($Lencnt/$clng);	
		//$divsr = ($Lencnt/$clng);	
		echo $Lencnt." : ".$divsr."<br>\n";
		$Lenlist = $Lencnt/$divsr;
		echo $Lenlist."<br>\n";
		echo '<table border="1" cellpadding="7px" cellspacing="0" summary=""><tr><td valign="top">';
		foreach ($listing as $val) {
   		echo '<a href="' . $val . '">' . $val . "<br>\n";
			$Lenlist = $Lenlist-1;
			if($Lenlist < 0) {
				echo '</td><td valign="top">';
				$Lenlist = $Lencnt/$divsr;
				}
		}
		echo '</td><td valign="top"><b><u>Directories</u></b><br><br>';
		$Lenlist = $Lencnt/$divsr;
		foreach ($dirs as $val) {
   		echo '<a href="' . $val . '">' . $val . "<br>\n";
			$Lenlist = $Lenlist-1;
			if($Lenlist < 0) {
				echo '</td><td>';
				$Lenlist = $Lencnt/$divsr;
				}
		}
		
		echo '</td></tr></table>';
	}
?> 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
I think you need to consider hiring a professional application developer who can get "hands-on" with your servers and data.  This is not really a question with an answer - it's a requirement for application development that is specific to your organization, client list, and data structures.  It's a simple application - we've all done these things before - and it will not cost you very much money to get a professional solution.

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.
http://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
0
peter-cooperAuthor Commented:
Thanks very much dave.
0
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.