Example #1
0
function wpcf7_cleanup_upload_files()
{
    if (is_admin() || 'GET' != $_SERVER['REQUEST_METHOD'] || is_robots() || is_feed() || is_trackback()) {
        return;
    }
    $dir = trailingslashit(wpcf7_upload_tmp_dir());
    if (!is_dir($dir) || !is_readable($dir) || !wp_is_writable($dir)) {
        return;
    }
    if ($handle = @opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." || $file == ".." || $file == ".htaccess") {
                continue;
            }
            $mtime = @filemtime($dir . $file);
            if ($mtime && time() < $mtime + 60) {
                // less than 60 secs old
                continue;
            }
            wpcf7_rmdir_p(path_join($dir, $file));
        }
        closedir($handle);
    }
}
Example #2
0
function wpcf7_cleanup_upload_files()
{
    $dir = trailingslashit(wpcf7_upload_tmp_dir());
    if (!is_dir($dir)) {
        return false;
    }
    if (!is_readable($dir)) {
        return false;
    }
    if (!is_writable($dir)) {
        return false;
    }
    if ($handle = @opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." || $file == ".." || $file == ".htaccess") {
                continue;
            }
            $stat = stat($dir . $file);
            if ($stat['mtime'] + 60 < time()) {
                // 60 secs
                @unlink($dir . $file);
            }
        }
        closedir($handle);
    }
}
Example #3
0
function wpcf7_cleanup_upload_files($seconds = 60, $max = 100)
{
    if (is_admin() || 'GET' != $_SERVER['REQUEST_METHOD'] || is_robots() || is_feed() || is_trackback()) {
        return;
    }
    $dir = trailingslashit(wpcf7_upload_tmp_dir());
    if (!is_dir($dir) || !is_readable($dir) || !wp_is_writable($dir)) {
        return;
    }
    $seconds = absint($seconds);
    $max = absint($max);
    $count = 0;
    if ($handle = @opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file == "." || $file == ".." || $file == ".htaccess") {
                continue;
            }
            $mtime = @filemtime($dir . $file);
            if ($mtime && time() < $mtime + $seconds) {
                // less than $seconds old
                continue;
            }
            wpcf7_rmdir_p(path_join($dir, $file));
            $count += 1;
            if ($max <= $count) {
                break;
            }
        }
        closedir($handle);
    }
}