Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:44:47+00:00 2026-06-17T22:44:47+00:00

very common question and still did not find the right solution for this. I

  • 0

very common question and still did not find the right solution for this. I need to run cron job to start php script each morning to list all new files created on the web server during the night. This is very usefull to see what visitors have uploaded during the night and ofcourse very ofter those files could be harmful files that will hurt other visitors computers. So far I have this:

$dir = "../root/";         
$pattern = '\.*$'; // check only file with these ext.              
$newstamp = 0;                
$newname = "";    
if ($handle = opendir($dir)) {                   
       while (false !== ($fname = readdir($handle)))  {                
         // Eliminate current directory, parent directory                
         if (ereg('^\.{1,2}$',$fname)) continue;                
         // Eliminate other pages not in pattern                
         if (! ereg($pattern,$fname)) continue;                
         $timedat = filemtime("$dir/$fname");                
         if ($timedat > $newstamp) {    
            $newstamp = $timedat;    
            $newname = $fname;    
          }    
         }    
        }    
closedir ($handle);    

// $newstamp is the time for the latest file    
// $newname is the name of the latest file    
// print last mod.file - format date as you like                
print $newname . " - " . date( "Y/m/d", $newstamp);    

this prints the newest file but only in one directory root/ and doesnt check for example root/folder/ and etc.. How to do it recusrsivly ?
If I add a new file within root/folder the script will show me folder with date , but would not show which file in root/folder was created.. I hope you understand what I mean, thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:44:49+00:00Added an answer on June 17, 2026 at 10:44 pm

    Quick script that does what you want (tested under windows 7 with cygwin and under ubuntu 12.10 with PHP 5.3.10)

    <?php
    $path = $argv[1];
    $since = strtotime('-10 second'); // use this for previous day: '-1 day'
    
    $ite = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
    foreach ( new RecursiveIteratorIterator($ite) as $filename => $object ) {
        if (filemtime($filename) > $since) {
          echo "$filename recently created\n";
        }
    }
    

    My quick test:

    $> mkdir -p d1/d2
    $> touch d1/d2/foo
    $> php test.php .
    ./d1/d2/foo recently created
    $> php test.php . # 10secs later 
    $>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this question is about style, because i think this is a very common problem
This is a very common but rarely solved topic. I seriously need some help
This should be a very common question for developers who used setup.py to build
I think this is a common and typical question from novices but I still
I've googled around and found this question very common but I can't seem to
I know this is a very common question, but I would like to know
I guess it's a very common question, it's a pitty I can't find the
This seems to be a very common problem, but still I haven't found a
This is one very common question asked again and again on stack overflow and
I know this question has been asked multiple times (however, I could still not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.