Page 2 of 2

Posted: Fri Oct 27, 2006 1:41 pm
by volka
akimm wrote:Did I over complicate?
yes

Code: Select all

<?php
$threshold = time() - (86400 * 10);

foreach ( glob('*.*') as $filepath ) {
	$created = filectime($filepath);
	
	if ($created > $threshold) {
		echo '*new* ';
	}
	echo $filepath, ' - ', date('Y-m-d H:i:s', $created), "<br />\n";
}
?>

Posted: Fri Oct 27, 2006 1:43 pm
by akimm
Thanks Feyd, i'll see about changing that.

Posted: Fri Oct 27, 2006 1:47 pm
by akimm
Volka, why do you want the interger 864k minus this time?

Posted: Fri Oct 27, 2006 1:54 pm
by feyd
That's the calculation for ten days ago.

Posted: Fri Oct 27, 2006 1:58 pm
by akimm
so its all in seconds, ok.. I was thinking that I was just not sure. Thanks for clarification.

Posted: Fri Oct 27, 2006 2:21 pm
by volka

Code: Select all

$threshold = strtotime('now - 10 days');
// or
$threshold = strtotime('today - 10 days');
might be more intuitive.
And yes, unix timestamps are in seconds (since start of epoche).

Posted: Sat Oct 28, 2006 10:50 am
by akimm
Volka, I have tried your solution, and many others by experimenting with different variables, and implementing different ones. It always has the same result, it prints all the files, its like it ignores the time comparrison.

Code: Select all

<?php
error_reporting (E_ALL);
$img = "<img src=http://www.akimm.com/images/new1.gif>";
$threshold = strtotime('today - 10 days');
$path = "article/";
foreach(glob($path . "/*.txt") as $file) {
        $created = filectime($file);
        $file = basename($file);
        $compare = ($created - $threshold);
        if ($compare <= 10) {
                echo "<ul>" . "<li>" . $img .  $file . "<a href=http://www.akimm.com/philosophy.php>" .  "   Click to view " . "</a>" . "</li>" . "</ul>";
												#break;
        } else {
echo "<br />" . "<br />" . "no new articles, add one by" . "<a href=http://www.akimm.com/add_art.php>" . "  clicking here " . "</a>";
												break;
				}
			}
?>

Posted: Sat Oct 28, 2006 10:51 am
by akimm
If you are wondering, I added basename, cuz everytime it printed the $file it printed a leading article/ before it, which messed up my CSS a bit, so I stripped that with basename, as for the addition of variables, I did that because nothing else was working. This still doesn't do the trick.

I even recently tried this,

Code: Select all

$today = strtotime('today');
foreach(glob($path . "/*.txt") as $file) {
        $created = filectime($file);
        $file = basename($file);
        $compare = ($created - $threshold);
        if ($compare <= $today)
Still no luck.

Posted: Sat Oct 28, 2006 11:17 am
by volka
What's the output of

Code: Select all

<?php
$threshold = time() - (86400 * 10);

foreach ( glob('article/*.txt') as $filepath ) {
	$created = filectime($filepath);
	if ($created > $threshold) {
		echo '*new* ';
	}
	echo $filepath, ' - ', date('Y-m-d H:i:s', $created), "<br />\n";
}
?>
without any changes?

Posted: Sat Oct 28, 2006 12:01 pm
by akimm
"article/Foley\'s Adventure1.txt - 2006-10-05 13:12:37
article/Sleepless, i step into insanity.2.txt - 2006-10-06 01:41:39
*new* article/s6.txt - 2006-10-28 11:47:13"

Only the bottom one is actually new.

Posted: Sat Oct 28, 2006 12:13 pm
by volka
akimm wrote:"article/Foley\'s Adventure1.txt - 2006-10-05 13:12:37
article/Sleepless, i step into insanity.2.txt - 2006-10-06 01:41:39
*new* article/s6.txt - 2006-10-28 11:47:13"

Only the bottom one is actually new.
And only the last entry is marked as *new* => the actual comparison is working.

Posted: Sat Oct 28, 2006 12:52 pm
by akimm
Yea, but it prints all, the way the program is written I thought it would print only the new files. Believe it or not, I had this working some time ago, then I tried to add some functionallity to it, and messed it all up.

Posted: Sat Oct 28, 2006 12:54 pm
by volka
Don't know what you did.

Posted: Sat Oct 28, 2006 12:57 pm
by akimm
yea me either, I will keep trying, I'll post some codes, up later, maybe someone will notice something wrong after I do some BIO hw on work on this some more..

See ya, thanks for the help you've given.