Primer Commit
This commit is contained in:
26
verificaciones/guardar_fotos.php
Normal file
26
verificaciones/guardar_fotos.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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.']);
|
||||
}
|
||||
Reference in New Issue
Block a user