php method to delete expired files: [public function download_project($array)$tmp = 'tmp_down';$savepath1 = '../public'.$tmp;$path1 = dir(...] .
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); } } }
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!