How to delete expired files in php

王林
Release: 2023-03-13 09:54:01
Original
1435 people have browsed it

php method to delete expired files: [public function download_project($array)$tmp = 'tmp_down';$savepath1 = '../public'.$tmp;$path1 = dir(...] .

How to delete expired files in php

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

You must have encountered such a situation, server The disk space occupied is 100%. The reason may be that the temporary folder for project package download is full.

So how should we solve this problem? In fact, it is very simple, just

Solution: Clear the expired files before each download so that they will not take up disk space.

Specific code:

public function download_project($array) { // 循环删除过期文件 start $tmp = 'tmp_down'; $savepath1 = '../public'.$tmp; $path1 = dir($savepath1); while (($item = $path1->read())!=false) { if($item=='.' || $item=='..'){ continue; }else{ $file = $savepath1.'/'.$item; $times = time()-filemtime($file); if($times>24*3600){ unlink($file); } } }
Copy after login

Recommended learning:php training

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

Related labels:
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 admin@php.cn
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!