Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-08-2006, 08:58 PM filemtime question
Yak Yak Yak Yak Yak

Posts: 593
Location: Rochester, MN
Trades: 0
I am trying to select only files that were modified on a specific date, and display them.

For example, pull all files that were modified today, and display them in the output. Is there a way to do this? Here is the code I am using:

Code:
<?php
if ($handle = opendir('11262005/')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
          echo "$file\n";
       }
   }
   closedir($handle);
}
?>
Can someone help me with this? I will start using a time stamp in the future, but that won't help me with the current files.

Also, is there a way to sort the entire contents of the directory by modification date?

Thanks in advance.

Frank
__________________

Please login or register to view this content. Registration is FREE
neorunner is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-09-2006, 05:54 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
PHP Code:
<?php
clearstatcache
();
$today strtotime(date("d M Y"));
$filelist = Array();
$times = Array();
if (
$handle opendir('images/')) {
  while (
false !== ($file readdir($handle))) {
    if (
$file != "." && $file != "..") {
      
$time filemtime("images/".$file);
      if(
$today-$time <0) {
    
$filelist[] = $file;
    
$times[] = $time;
      }      
    }
  }
  
closedir($handle);
}


array_multisort($timesSORT_NUMERICSORT_ASC$filelist);
?>
<style>
td { border: solid 1px black; }
th { border: solid 1px black; }
</style>
<table><tr>
<th>Filename</th><th>Last Modified</th>
</tr>
<?
for($i 0$i count($filelist); $i++) {
  echo 
"<tr><td>".$filelist[$i]."</td><td>".date("jS M Y, h:i:s",$times[$i])."</td></tr>";
}

echo 
"</table>";

?>
Some explanation:

$today = strtotime(date("d M Y")); gets a timestamp value for the start of the day. By subtracting the file mod times from this, we can tell if it has been modified to day ( the result will be negative ).

the lines $filelist[] = $file; and $times[] = $time; are building up two arrays, one of times, and the other of files. Only files modified today will be in the lists.

array_multisort sorts both arrays by the time last modified, keeping the files with their times. To alter the sort order you can change SORT_ASC to SORT_DESC.

The rest of the code just prints it all out in a nice table.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to filemtime question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22334 seconds with 12 queries