我有一个包含大量文件的文件夹。我的目标是在备份完要删除的文件后,根据创建或修改的日期逐年备份文件。
实际上,我的服务器包含大小为20GB的pdf文件,我想备份这些文件,但是应该每年进行一次文件夹备份。但是我不知道如何实现这一目标。
$dir_path = "/pdfs/";
$pdf_arr = scandir($dir_path);
foreach($pdf_arr as $file) {
if($file ! == '.' && $file ! == '..') {
print_r($file);
}
}
// year and month wise backup
public function getLastModifiedFiles() {
$source = public_path("pdfs");
$destination = public_path("destination");
$smallest_time=INF;
$oldest_file='';
if ($handle = opendir($source)) {
while (false !== ($file = readdir($handle))) {
if($file !== '.' && $file !== '..') {
$time = filemtime($source.'/'.$file);
$mm = date('m', $time);
$yr = date('Y', $time);
\File::isDirectory($destination.'/'.$yr."/$mm") or \File::makeDirectory($destination.'/'.$yr."/$mm", 0777, true, true);
$moveFile="$destination/$yr/$mm/$file";
//dd($source.'/'.$file);
if(!is_dir($source.'/'.$file)) {
if (copy($source.'/'.$file, $moveFile))
{
unlink($source.'/'.$file);
}
}
}
}
closedir($handle);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句