PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi..
What I want is to have an updated section on my main page.. This section will display all the files in all the folders that have been updated in the past 3 months..
Here is my problem..
Eg.. My folders are like this:
-- documents
-->new
-->written
-->others
I do have a function .inc file and a php file wich uses the function to display the files and folders in a particular dir. But I have to have these two files in each folder to be able to make it work as I'm using getcwd().. I can't set the directory path.. coz it'll give me an error..
How do I go through all the files and pick out only the ones that have been updated in the past 3mths all in one php page? Let's say i wanna put that php page in the documents folder...
use filectime() to determine when they were last changed (see details at php.net)
before that you got to take the current timestamp an substract 90(days)*24(hours)*60(minutes)*60(seconds) ... then you can compare the two values.
concerning the filenames, if you have unix try:
$file_list=shell_exec("ls -1 /dir/dir/new/*.*");
then use explode:
$file_array=explode("\n",$file_list);
then you can process each file with using foreach()
<?php
function getDirList($base)
{
$base_array = array();
if(is_dir($base)) // if it is a dir
{
$diropen = opendir($base); // open dir
while (false !== ($dir = readdir($diropen))) // stop when $dir=false
{
// get rid of the folders that need not be displayed
// if base.subdir name is a dir
if (is_dir($base.$dir) && $dir !== '.' && $dir !== '..' && $dir !== 'drop box' && $dir !== '.DS_Store')
{
$subs = $dir;
$subbase = strval($base.$dir."/"); // entire filename
getDirList($subbase); //recursive
}
if(is_file($base.$dir) && $dir !== '.' && $dir !== '..' && $dir !== 'drop box' && $dir !== '.DS_Store')
{
$subs = $dir;
$subbase = strval($base.$dir); // entire filename
$filedate = date("m/d/y", filemtime($subbase)); // get filedate
$todaydate=date('m/d/y'); // get today's date
$diffmths = monthsApart($filedate, $todaydate);
if($diffmths < 3) // print out the files where the mths diff is 3
{
if(!strstr($dir, ".php")) // take out the .php files
{
// HERE IS WHERE I WANNA SORT
print "<a href="./$subbase" class=mycssname>$dir</a><br>";
print "file : $subbase<br>";
print "filedate: $filedate<br>";
}
}
}
}
closedir($diropen); // close dir
}
else // if it is not a dir
{
print "no dir";
next;
}
}
function monthsApart($oldDate,$newDate)
{
list($oldMonth,$oldDay,$oldYear) = split("/",$oldDate);
list($newMonth,$newDay,$newYear) = split("/",$newDate);
$diff = (($newDay>=$oldDay?0:-1) + ($newYear-$oldYear)*12)+$newMonth-$oldMonth;
return abs($diff);
}
?>
if you figure out how to build it as an associative array, use the date to call the filename, and a second array with date (in unicx timestamp) and then use rsort (largest first... use the natural order version though) on themand then iterate throughthe date array using that to call the file to list when making the list