"no id"]); exit; } $id = preg_replace('/[^a-z0-9]/i', '', $id); $cfile = $dir . "cb_{$id}.json"; // clipboard actual del cliente $sfile = $dir . "set_{$id}.txt"; // texto a setear en cliente // ── CLIENTE sube su clipboard actual ── // POST ?action=upload&id= body=texto plano if ($action === "upload") { $text = file_get_contents("php://input"); file_put_contents($cfile, json_encode([ "text" => $text, "ts" => microtime(true) ]), LOCK_EX); echo json_encode(["status" => "ok"]); exit; } // ── CLIENTE consulta si hay texto para setear ── // GET ?action=poll&id= if ($action === "poll") { if (!file_exists($sfile)) { echo json_encode(["set" => null]); exit; } $text = file_get_contents($sfile); unlink($sfile); echo json_encode(["set" => $text]); exit; } // ── PANEL lee clipboard del cliente ── // GET ?action=get&id= if ($action === "get") { if (!file_exists($cfile)) { echo json_encode(["text" => null, "ts" => 0]); exit; } $data = json_decode(file_get_contents($cfile), true); echo json_encode($data); exit; } // ── PANEL escribe al clipboard del cliente ── // POST ?action=set&id= body=texto plano if ($action === "set") { $text = file_get_contents("php://input"); file_put_contents($sfile, $text, LOCK_EX); echo json_encode(["status" => "ok"]); exit; } echo json_encode(["error" => "invalid action"]);