| Server IP : 127.0.0.1 / Your IP : 216.73.216.109 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10 System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64 User : SERVERWEB ( 0) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/laragon/www/app/ |
Upload File : |
<?php
header('Content-Type: application/json; charset=utf-8');
$avisosDir = __DIR__ . '/avisos';
$avisosUrl = 'app/avisos/';
$timezone = new DateTimeZone('America/La_Paz');
$today = new DateTimeImmutable('today', $timezone);
$activeAvisos = [];
if (is_dir($avisosDir)) {
$files = scandir($avisosDir);
foreach ($files as $file) {
if (!preg_match('/^aviso-(\d{2})-(\d{2})-(\d{2})\.(jpg|jpeg|png|webp)$/i', $file, $matches)) {
continue;
}
$day = (int) $matches[1];
$month = (int) $matches[2];
$year = 2000 + (int) $matches[3];
if (!checkdate($month, $day, $year)) {
continue;
}
$expiresAt = DateTimeImmutable::createFromFormat(
'!Y-m-d',
sprintf('%04d-%02d-%02d', $year, $month, $day),
$timezone
);
if ($expiresAt && $expiresAt >= $today) {
$activeAvisos[] = [
'file' => $file,
'url' => $avisosUrl . rawurlencode($file),
'expires' => $expiresAt->format('Y-m-d'),
];
}
}
}
usort($activeAvisos, function ($a, $b) {
return strcmp($b['expires'], $a['expires']);
});
echo json_encode([
'active' => !empty($activeAvisos),
'aviso' => $activeAvisos[0] ?? null,
]);