Delete the file before a certain period of time

/ *
 * Delete the file folder created before $ n minute
 * @param $ directory, dir physical paths to be processed, without end \
 * @param $ n expiration time, in minutes
 * @return void
 * /
function z_del_file_by_ctime ($ the dir, n-$) {
    IF (is_dir ($ the dir)) {
        IF (DH = the opendir $ ($ the dir)) {
            the while (to false! == ($ File = the readdir ($ DH))) {
                IF ($ !. ""! = && File File $ = "..") {
                    $ $ fullpath the dir = "/" $ File;..
                    IF) {(is_dir ($ fullpath!) 
                        $ FILEDATE The filemtime = ($ fullpath);
                        $ = round minutes ((Time () - $ FILEDATE) / 60);
                        IF (minutes $> $ n-)
                            The unlink ($ fullpath); // delete files
                    }
                }
            }
        }
        Closedir ($ DH);
    }
}


// This is the code calling
// Remove Document 1 days before
$ the dir = The realpath ( './ the Upload / Export');
z_del_file_by_ctime (the dir $, 24 * 60);
%>

Guess you like

Origin www.cnblogs.com/jingxiaoniu/p/11497691.html