删除3天以前的日志文件,Fatal error,该怎么解决

WBOY
Release: 2016-06-13 10:16:57
Original
730 people have browsed it

删除3天以前的日志文件,Fatal error
我不懂PHP,现在想实现一个功能,删除指定目录中三天以前的文件(日志),就在百度上找的一个删除目录的函数,如下

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->    function del_directory($dir){        if(!($mydir = @dir($dir))){            return;        }        while($file = $mydir->read()){            if(is_dir("$dir$file") && $file!='.' && $file!='..'){                @chmod("$dir$file", 0777);                del_dir("$dir$file");            }elseif(is_file("$dir/$file")){                [email protected]($file);//读取文件的最后更新时间                if(time() - $file_time > 3600 * 24 * 3){                    @chmod("$dir/$file", 0777);                    @unlink("$dir/$file");                }            }        }        $mydir->close();        @chmod($dir, 0777);        @rmdir($dir);    }
Copy after login

报错:Fatal error: Unsupported operand types in D:\wamp\www\Player\playlogviewer.php on line 36
对应的是这一行代码:if(time() - $file_time > 3600 * 24 * 3)

麻烦看看是什么问题,谢谢!



------解决方案--------------------
PHP code
$stat = @stat($file);$file_time=$stat['mtime'];//读取文件的最后更新时间<br><font color="#e78608">------解决方案--------------------</font><br>致命错误:不支持的操作数据类型<br>产生原因,将不符合数据类型的数据传送给了某些函数。尤其是容易出现在将一个数组传给了一个函数,这个函数应该接受的参数是数字。<br><font color="#e78608">------解决方案--------------------</font><br>if(time() - $file_time > 3600 * 24 * 3)<br>你把它用()分开试试<br>if((time()-$file_time)>(3600*24*3)){}<br><font color="#e78608">------解决方案--------------------</font><br>array stat ( string $filename );<br>返回的是数组。<br>  [email protected]($file);//读取文件的最后更新时间<br>  if(time() - $file_time > 3600 * 24 * 3){         //这里就要用数组的。去查一下stat ()<br><br>用 $stat['mtime']<br><div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!