How to delete files by time in PHP?

Guanhui
Release: 2023-03-01 15:26:01
Original
3008 people have browsed it

How to delete files by time in PHP?

#How to delete files by time in PHP?

First use the function "opendir()" to read all files in the folder; then use the function "is_dir()" to filter out the folder; then use the function "filemtime()" to get the file creation time; finally delete it according to the creation time.

Code example

$n) unlink($fullpath); //删除文件
                    }
                }
            }
        }
        closedir($dh);
    }
}


//下面是调用的代码
//删除1天前的文件
$dir = realpath('./Upload/export');
del_file_by_ctime($dir, 24*60);
?>
Copy after login

Recommended tutorial: "PHP"

The above is the detailed content of How to delete files by time in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!