You are here: Re: To cange the last modidied date of a file « PHP Programming Language « IT news, forums, messages
Re: To cange the last modidied date of a file

Posted by Pedro Graca on 01/21/06 01:17

Steel wrote:
>
> <?php
> clearstatcache();
> $FileName = 'sem.txt';
> $origtime = getdate(filemtime($FileName));
>
> //these following date are they of some type?
> $Today=strtotime("now");
> $Modifile=filemtime($FileName);

Yes. Now it's ok to compare them. They're both UNIX timestamps.

But I'd do it /just/ a little differently. You're calling the function
filemtime() twice but you may remove one of those calls with some
reordering of the lines.

$FileName = 'sem.txt'; ### repeated to mark changes
$Modifile = filemtime($FileName);
$origtime = getdate($Modifile);
$Today = strtotime("now"); ### repeated to mark changes


> if ($Today>$Modifile)
> {
> $newtime = mktime(2, 0, 0, $origtime['mon'],
> 1+$origtime['mday'],$origtime['year']);
> touch($FileName, $newtime);

So, if you do this shortly before midnight, the new file time will be
set to "expire" in a little more than two hours. If you don't mind about
such a short time, that's ok :-)

> if ($handle = opendir('./cgi-bin/sessions')) {
>
> while (false !== ($file = readdir($handle))) {
> if ($file != "." && $file != "..")
> {unlink("./cgi-bin/sessions/" . $file);}
> }

You need to work on your indenting :-)

> closedir($handle);
> }
> }
> ?>
>
> Now work?

Looks like it should. I didn't test it.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация