27 lines
881 B
PHP
27 lines
881 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
$uploadDir = __DIR__ . '/verificaciones/';
|
|
$mediaUrl = 'https://adminttl.test/verificaciones/verificaciones/'; // Cambia esto según tu dominio
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image'])) {
|
|
$image = $_FILES['image'];
|
|
$ext = pathinfo($image['name'], PATHINFO_EXTENSION);
|
|
$filename = uniqid('img_', true) . '.' . $ext;
|
|
$targetPath = $uploadDir . $filename;
|
|
|
|
if (!is_dir($uploadDir)) {
|
|
mkdir($uploadDir, 0755, true);
|
|
}
|
|
|
|
if (move_uploaded_file($image['tmp_name'], $targetPath)) {
|
|
echo json_encode(['url' => $mediaUrl . $filename]);
|
|
} else {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => 'No se pudo guardar la imagen.']);
|
|
}
|
|
} else {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'No se recibió ninguna imagen.']);
|
|
}
|