Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Delete old files function won't work

    Anyone know why this won't work?
    I can't see anything wrong.
    PHP Code:
    function DeleteOldFiles($path) {
      if (
    $handle opendir($path)) {
         while (
    false !== ($file readdir($handle))) {
            if ((
    time()-filemtime()($path.$file) >= 2*24*60*60// 2 days {  
               
    if (preg_match('/\.log$/i'$file)) {
                  
    unlink($path.$file);
               }
            }
         }
       }
    }
    DeleteOldFiles('./logs/'); 
    Last edited by sonny; 08-19-2012 at 06:23 AM.

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You've commented out a bracket { so the syntax is wrong. But you haven't correctly supplied the argument for filemtime():

    Code:
    if ((time()-filemtime($path.$file) >= 2*24*60*60) { // 2 days
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Thanks, I looked at that code, or at least I thought so, how the heck
    I left out the path, and commented out my bracket, I think I need to
    stop for the night before I really start screwing things up.

    Thanks
    Sonny


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •