Delete the log file 3 days ago, Fatalerror. how can this problem be solved?

Source: Internet
Author: User
Tags unsupported
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) {deletes 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 ")) {$ file_time = @ stat ($ file); // The last update time when the file is 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.
$ File_time = @ stat ($ 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']

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.