Page 1 of 1
HELP!! Retreiving (updated) files from all folders
Posted: Tue Aug 05, 2003 9:40 pm
by parkin
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...
Any help is much needed...
Thanks..
Posted: Wed Aug 06, 2003 1:01 am
by Tubbietoeter
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()
Posted: Fri Aug 08, 2003 12:26 am
by parkin
i've managed to figure it out..
Still new at this.. I'm kinda stuck at sorting..

I want to print out the filenames which have the latest date first...
Code: Select all
<?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);
}
?>
Any help.. IS MUCH APPRIECIATED!

thanks

Posted: Fri Aug 08, 2003 9:35 am
by m3rajk
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
associative array
Posted: Tue Aug 12, 2003 12:57 am
by parkin
hmm.. I think i'm slow at picking up php...
this is how i tried to use associative array to sort.. but it's not working out.. it displays in the same format as when i did not sort it..
help?
Code: Select all
<?php
if($diffmths < 3)
{
if(!strstr($dir, ".php")) // take out the .php files
{
//print "file : $subbase<br>";
// create associative array
$update_array = array("filename"=> "$dir", "dates"=> "$filedate");
$date_array = array($filedate);
rsort ($date_array);
reset ($date_array);
//print "$update_array[dates]";
print "<font size=-1 face="Arial">";
print "<tr>";
for($i=0; $i<sizeof($date_array);$i++)
{
$date_one = $date_array[$i];
if($date_one == $update_array[dates])
{
print "<td width=300>";
print "<a href="./$subbase" class=mycssname>$update_array[filename]</a><br>";
print "</td>";
print "<td width=100>";
print "$update_array[dates]<br>";
print "</td>";
}
else
{
next;
}
}
print "<tr>";
print "</font>";
?>
thanks for help..
