-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathestadoDescarga.php
More file actions
33 lines (28 loc) · 974 Bytes
/
estadoDescarga.php
File metadata and controls
33 lines (28 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/**
* estadoDescarga.php
* Indica al frontend el estado de exportarPedidos.php.
* Responde inmediatamente con JSON.
*/
header('Content-Type: application/json; charset=UTF-8');
header('Cache-Control: no-store');
$token = preg_replace('/[^a-z0-9]/', '', strtolower($_GET['token'] ?? ''));
if ($token === '') {
echo json_encode(['iniciado' => false, 'terminado' => false]);
exit;
}
$dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'ecommerce_exports' . DIRECTORY_SEPARATOR;
$statusFile = $dir . $token . '.started';
$doneFile = $dir . $token . '.done';
// Limpiar caché de stat de PHP para obtener estado real del disco
clearstatcache(true, $statusFile);
clearstatcache(true, $doneFile);
$terminado = file_exists($doneFile);
if ($terminado) {
// Limpiar el archivo .done para no detectarlo dos veces
@unlink($doneFile);
}
echo json_encode([
'iniciado' => file_exists($statusFile) || $terminado,
'terminado' => $terminado,
]);