Files
sam-kd/voice_ai/cleanup_cron.php

25 lines
822 B
PHP
Raw Normal View History

<?php
// DB 연결 필요
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
// 1주일 지난 파일 조회
$sql = "SELECT id, audio_file_path FROM meeting_logs WHERE file_expiry_date < NOW() AND audio_file_path IS NOT NULL";
$stmt = $pdo->query($sql);
$expired_files = $stmt->fetchAll();
foreach ($expired_files as $file) {
$full_path = $_SERVER['DOCUMENT_ROOT'] . $file['audio_file_path'];
// 파일 삭제
if (file_exists($full_path)) {
unlink($full_path);
}
// DB 업데이트 (파일 경로는 지우고 기록은 남김)
$update_sql = "UPDATE meeting_logs SET audio_file_path = NULL WHERE id = ?";
$pdo->prepare($update_sql)->execute([$file['id']]);
echo "Deleted: " . $full_path . "\n";
}
?>