mirror of
https://github.com/cheveguerra/Colaborando.git
synced 2026-08-19 00:46:37 +00:00
Commit inicial
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
$file = 'datos.json';
|
||||
|
||||
if (isset($_GET['nombre']) && $_GET['nombre'] != '') {
|
||||
$nombre = basename($_GET['nombre']); // 'basename' ayuda a evitar que intenten acceder a carpetas superiores
|
||||
// Si el nombre no termina en .json, se lo agregamos
|
||||
if (pathinfo($nombre, PATHINFO_EXTENSION) != 'json') {
|
||||
$nombre .= '.json';
|
||||
}
|
||||
$file = $nombre;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
file_put_contents($file, json_encode($data['data'], JSON_PRETTY_PRINT));
|
||||
echo json_encode(['status' => 'success', 'data' => ['message' => 'Data saved successfully']]);
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
if (file_exists($file)) {
|
||||
$data = file_get_contents($file);
|
||||
echo json_encode(['status' => 'success', 'data' => json_decode($data)]);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'data' => ['message' => 'File not found']]);
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'data' => ['message' => 'Invalid request method']]);
|
||||
}
|
||||
Reference in New Issue
Block a user