auto delete files more than 50 days

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    auto delete files more than 50 days

    help everyone!.i want a php script that auto delete files more than 50 days on my website.thanks

    #2
    use cron job mate..

    Comment


      #3
      have a sql with the uploaded date, then use php cli to check the uploaded file against the current date, if it is older then 50 days unlink the file and remove the sql entry

      PHP Code:
      foreach ($_SERVER as $server => $value)
      {
      echo 
      "$server is $value<br />";

      Comment


        #4
        By amylee:

        PHP Code:
        $path dirname(__FILE__).'/files'
          if (
        $handle opendir($path)) { 

            while (
        false !== ($file readdir($handle))) { 
                if ((
        time()-filectime($path.'/'.$file)) < 86400) {  // auto-deletion every 24 hours 
                  
        if (strripos($file'.txt') !== false) { //deletes particular file extension 
                    
        unlink($path.'/'.$file); 
                  } 
                } 
            } 
          } 
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment


          #5
          Use cron job with a command included php file

          Comment


            #6
            Originally posted by arnage View Post
            By amylee:

            PHP Code:
            $path dirname(__FILE__).'/files'
              if (
            $handle opendir($path)) { 

                while (
            false !== ($file readdir($handle))) { 
                    if ((
            time()-filectime($path.'/'.$file)) < 86400) {  // auto-deletion every 24 hours 
                      
            if (strripos($file'.txt') !== false) { //deletes particular file extension 
                        
            unlink($path.'/'.$file); 
                      } 
                    } 
                } 
              } 

            Thanks guys..seems cron job is simpler,bt i stil find this code useful..thanks

            Comment


              #7
              4320000 seconds in 50 days to modify the date function above.

              Comment


                #8
                Originally posted by Busary View Post
                Thanks guys..seems cron job is simpler,bt i stil find this code useful..thanks
                make a new cron job as like
                get delete.php
                (delete.php is the file which include the code)

                Comment

                Working...
                X