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 ']