Delete log files from 3 days ago, Fatal error, how to resolve

Source: Internet
Author: User
Tags unsupported
Delete log files from 3 days ago, Fatal error
I do not understand PHP, now want to implement a function, delete the specified directory three days before the file (log), on the Baidu search for a delete directory function, as follows
PHP Code
  
       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);//Read the last updated time of the file                if ()-$file _time > 3600 * 24 * 3) {                    @chmod ("$dir/$file", 0777);                    @unlink ("$dir/$file");        }}} $mydir->close ();        @chmod ($dir, 0777);        @rmdir ($dir);    }

Error: Fatal error:unsupported operand types in D:\wamp\www\Player\playlogviewer.php on line 36
Corresponds to this line of code: if (Time ()-$file _time > 3600 * 24 * 3)

Trouble to see what is the problem, thank you!



------Solution--------------------
PHP code
 $stat = @stat ($file); $file _time= $stat [' Mtime '];// The last update time to read the file 
------solution--------------------
Fatal error: The unsupported operation data type
produces a reason for transferring data that does not conform to the data type to some functions. In particular, it is easy to pass an array to a function, and the function should accept the number of arguments.
------Solution--------------------
if (Time ()-$file _time > 3600 * 3)
You try it () separately
if (time ()-$file _ Time) > (3600*24*3)) {}
------solution--------------------
Array Stat (string $filename);
returns an array.
[email protected] ($file);//Read file Last updated
if (time ()-$file _time > 3600 * 24 * 3) {//This will be used in arrays. Check Stat. ()

with $stat [' Mtime ']
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.