Re: filemtype not working ?!?
| From: | David Robley | Date: | Wed, 14 Jun 2000 06:38:21 +0000 |
| Subject: | Re: filemtype not working ?!? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1818@lists.php.net to get a copy of this message | ||
On 13 Jun, Mario de Mello Bittencourt Neto wrote:
> Hi all,
> I am am writing a small script to manage my httpd log files. I am
> organizing then in a year/month way so I've decided to check the files
> last modified time in order to find out where does it belong.
>
> Unfortunatelly even tough I've managed to make it work under a
> regular directory whenever I try to run it in /var/log/httpd it show's
> me that every file it 1969/12/31...
>
> I wrote the small example bellow.
>
> if(!isSet($diretorio))
> { $diretorio = "/var/log/httpd/" ; }
>
> // mktime(int hour, int minute, int second, int month, int day, int
> year)
> $tsMonth = mktime(0,0,0,date("m"),1,date("Y")) ;
>
> $handle=opendir($diretorio);
> while ($file = readdir($handle))
> {
> if("dir" != filetype($file))
> {
> if(filemtime($file) < $tsMonth)
> {
> // I'll copy
> $year = date("Y",filemtime($file)) ;
> $month = date("m",filemtime($file)) ;
>
> $cmd = escapeShellCmd("cp ".$file."
> ".$pathBackup."/".$year."/".$month."/") ;
>
> echo $cmd."<br>" ;
> }
> }
>
> }
> closedir($handle);
I think your first problem is that $file is returning just the filename,
rather than the full path and file. Thus when you pass it to filemtime,
it looks in the current directory, finds no matching file and returns
'false' which is not a valid date. From there things go downhill. Try
prepending the value of $directorio to $file; make sure that you have
the last slash between the filename and the path.
You may ask why index.html works - my guess is that you have such a file
in the current working directory.
You could also test that $file is a file with the function
is_file(filename)
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA