I am experiencing some oddity when I am trying to use the filectime, filemtime or fileatime functions in PHP.
When I use it on files in a certain folder I seem to get accurate data, then when I use it on any other folder, it prints the files correctly, but the dates on them are all "19691231", which means it is returning false.
Can someone give me any tips on what might be wrong? I am use PHP 5.2 and it is on a Windows 2003 SP2 server.
Below is my code:
Basically it a function that will look at a folder, and go through each of it's files, looking at file size. If it has a date later than the current day minus the days entered (in this case 20) it will delete it. ... But I don't have it deleting yet, just printing some debug information so I can see what would happen.
Thanks!
<?php
//$dataDir = "C:\\Inetpub\\Apps\\website\\folder1"; //This folder it shows correct dates
$dataDir = "C:\\Inetpub\\Apps\\website\\folder1\\subfolder1"; $days = "20"; //Remove files going * days back
function removeFiles($dataDir, $days){ $d = dir($dataDir);
Take a look at your file_exists and filectime calls. In file_exists the path is $dataDir\\$entry. In teh filectime its just $entry. I think this is a good place to start. You don't have the patch right to the file in filectime.
Yeah, I'm not sure how I missed that. But it is very peculiar how it seemed to work for the one folder and not for others. But, it is working now. Thanks again!
Hello,
I am experiencing some oddity when I am trying to use the filectime, filemtime or fileatime functions in PHP.
When I use it on files in a certain folder I seem to get accurate data, then when I use it on any other folder, it prints the files correctly, but the dates on them are all "19691231", which means it is returning false.
Can someone give me any tips on what might be wrong? I am use PHP 5.2 and it is on a Windows 2003 SP2 server.
Below is my code:
Basically it a function that will look at a folder, and go through each of it's files, looking at file size. If it has a date later than the current day minus the days entered (in this case 20) it will delete it. ... But I don't have it deleting yet, just printing some debug information so I can see what would happen.
Thanks!
<?php
//$dataDir = "C:\\Inetpub\\Apps\\website\\folder1"; //This folder it shows correct dates
$dataDir = "C:\\Inetpub\\Apps\\website\\folder1\\subfolder1";
$days = "20"; //Remove files going * days back
function removeFiles($dataDir, $days){
$d = dir($dataDir);
while (false !== ($entry = $d->read())){
if ($entry != '..' && $entry != '.' && file_exists("$dataDir\\$entry"))
{
$fileDay = date("Ymd", filectime($entry));
$curDay = date(Ymd,(strtotime(date("Y-m-d"))-($days*86400)));
if ($curDay > $fileDay){
echo "$entry $fileDay $curDay DELETE<br>";
}else{
echo "$entry $fileDay $curDay KEEEP<br>";
}
}
}
$d->close();
}
removeFiles($dataDir, $days);
?>