【发布时间】:2020-03-05 10:32:33
【问题描述】:
我需要过去 7 天的存储日志来移动新文件夹。但是,我无法移动它们并收到此错误。
重命名(/var/www/html/eMarketing/storage/logs/old-log-2020-02-27,/var/www/html/eMarketing/storage/logs/laravel-2020-02-27.log ): 不是目录
我的代码在这里
public function logs()
{
$today = \Carbon\Carbon::today()->format('Y-m-d');
$days = \Carbon\Carbon::today()->subDays(7)->format('Y-m-d');
$newDirectoryPath = storage_path('logs/old-log-'.$days);
if (!\File::isDirectory($newDirectoryPath)) {
\File::makeDirectory($newDirectoryPath);
}
$path = storage_path('logs/');
$allFiles = \File::allFiles($path);
foreach($allFiles as $files) {
$file = pathinfo($files);
$logDay = str_replace('laravel-','', $file['filename']);
if ($logDay >= $days && $logDay < $today) {
\File::move($newDirectoryPath, $path.$file['basename']);
}
}
}
【问题讨论】:
-
/var/www/html/eMarketing/storage/logs目录是否存在? -
是的,这个目录存在@Jerodev
-
stackoverflow.com/questions/19139434/… 这能回答你的问题吗?