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!
Moderator: General Moderators
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 27, 2006 1:41 pm
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";
}
?>
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Fri Oct 27, 2006 1:43 pm
Thanks Feyd, i'll see about changing that.
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Fri Oct 27, 2006 1:47 pm
Volka, why do you want the interger 864k minus this time?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 27, 2006 1:54 pm
That's the calculation for ten days ago.
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Fri Oct 27, 2006 1:58 pm
so its all in seconds, ok.. I was thinking that I was just not sure. Thanks for clarification.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Oct 27, 2006 2:21 pm
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).
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sat Oct 28, 2006 10:50 am
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;
}
}
?>
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sat Oct 28, 2006 10:51 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Oct 28, 2006 11:17 am
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?
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sat Oct 28, 2006 12:01 pm
"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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Oct 28, 2006 12:13 pm
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.
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sat Oct 28, 2006 12:52 pm
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Oct 28, 2006 12:54 pm
Don't know what you did.
akimm
Forum Contributor
Posts: 460 Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh
Post
by akimm » Sat Oct 28, 2006 12:57 pm
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.