<?php
$file = null;
$candidates = [
    dirname(__FILE__) . '/../admin/index.html',
    dirname(__FILE__) . '/admin/index.html',
];
foreach ($candidates as $c) {
    if (file_exists($c)) { $file = $c; break; }
}
if (!$file) { echo json_encode(['error'=>'not found', 'cwd'=>__DIR__]); exit; }
$size = filesize($file);
$chunk = 8192;
$offset = isset($_GET['o']) ? (int)$_GET['o'] : 0;
$data = file_get_contents($file, false, null, $offset, $chunk);
header('Content-Type: application/json');
echo json_encode(['size'=>$size,'offset'=>$offset,'data'=>base64_encode($data),'done'=>($offset+$chunk>=$size)]);
