Find a file Age In php
I need to find the age of a file using php
for eg : i have abc.txt. I need to find how many days old.
ans: abc.txt is 20 day's old...
i have tried below code but i need only day's output
function humanTiming ($time)
{
// to get the time since that moment
$time = time() - $time;
// time unit constants
$timeUnits = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
// iterate over time contants to build a human
$humanTiming;
foreach ($timeUnits as $unit => $text)
{
if ($time < $unit)
continue;
$numberOfUnits = floor($time / $unit);
var_dump($humanTiming);
// human readable token for current time unit
$humanTiming = $humanTiming.' '.$numberOfUnits.'
'.$text.(($numberOfUnits>1)?'s':'');
// compute remaining time for next loop iteration
$time -= $unit*$numberOfUnits;
}
return $humanTiming;
}
$filename = 'H:\xampp\htdocs\doc\index.php';
if (file_exists($filename))
{
$time = strtotime('2010-04-28 17:25:43');
$time = filemtime($filename);
echo '<br/>File age is '.humanTiming($time).'.';
$elapsedTime = time()-filemtime($filename);
}
No comments:
Post a Comment