Simple function (or not? :D)


I need a help creating a simple function which will:

  1. Search the specified folder (which never changes) and its subfolders for files modified today.
  2. Trim the files names to leave only a string of 5 characters i.e. “order 0076789.pdf” to be trimmed to “76789”
  3. Save the above strings in an array, .json or any other useful variable/format
  4. Do 2,3&4 for a different folder
  5. Display the html with a table with 3 columns - 1st column with a list of values from 3 - 2nd column with a list of values from 4. and the last columns with values of 1st cloumn minus 2nd cloumn - i.e. if 76789 is in both 1st and 2nd - do not display it in 3rd.
  6. referesh the page when a new file is created in either folder.



Have you tried anything so far to accomplish what you are after?


I was trying with javascript and the File API - but it seems php is the more obvious tool.

What I have tried in php was something like the below but it gives me a list of of files with the metadata and I don;t know how to iterate over this output :blush:


$directory = 'c:/temp/data/';

$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));

 * @var string $filename
 * @var SplFileInfo $file
foreach ($it as $filename => $file) {
    if ($file->isDir()) {
    echo $filename . ' : ' . date('Y-m-d H:i:s', $file->getMTime()), PHP_EOL;


Is this going to be run on a local machine, or a server that holds all of the files?

function getContents($dir) {
    $files = [];
    $a = scandir($dir);
    foreach($a as $file) {
        if($file != '.' && $file != '..') {
           array_push($files, $file);
    return $files;

print_r(getContents( 'c:/temp/data/'));


Thank you.
I will try your approach.

Btw everything to be ran on the local machine which also serves as a server. I have tried to achieve this with java script - knows about limitations of accessing files on the client’s side.