Delete the log file 3 days ago. Fatalerror: I don't know PHP. now I want to implement a function to delete the files (logs) from the specified directory three days ago ), the following PHPcodefunctiondel_directory ($ dir) {if (! ($ Mydir @ dir ($ dir) {return; delete the log file 3 days ago, Fatal error
I don't understand PHP. now I want to implement a function. to delete the files (logs) in the specified directory three days ago, I will find a function to delete the directory on Baidu, as shown below:
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); // The last update time of the file to be read. if (time ()-$ 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
This line of code corresponds to: if (time ()-$ file_time> 3600*24*3)
Please check out what the problem is. thank you!
------ Solution --------------------
PHP code
$ Stat = @ stat ($ file); $ file_time = $ stat ['mtime']; // The last update time when the file is read.
------ Solution --------------------
Fatal error: unsupported operation data type
Cause: data that does not conform to the data type is transferred to some functions. In particular, it is easy to pass an array to a function. this function should accept numbers as parameters.
------ Solution --------------------
If (time ()-$ file_time> 3600*24*3)
Try separating it ()
If (time ()-$ file_time)> (3600*24*3 )){}
------ Solution --------------------
Array stat (string $ filename );
Returns an array.
[Email protected] ($ file); // The last update time when the file is read.
If (time ()-$ file_time> 3600*24*3) {// array is used here. Check stat ()
Use $ stat ['mtime']