<?php
// photo_upload.php
include 'connect.php';
$uploadId = intval($_POST['upload_id']);

$allowed = ['image/jpeg', 'image/jpg', 'image/png','image/pdf'];


if ($_FILES['photo']['error'] === UPLOAD_ERR_OK) {
    $ext  = pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION);
    $name = uniqid('photo_') . ".{$ext}";
    $path = 'uploads/images/' . $name;
    move_uploaded_file($_FILES['photo']['tmp_name'], $path);
    // update record
    $stmt = $conn->prepare("UPDATE camp_upload SET form_upload = ? WHERE id = ?");
    $stmt->bind_param('si', $path, $uploadId);
    $stmt->execute();
    echo json_encode(['success'=>true,'message'=>'Photo path updated']);
} else {
    echo json_encode(['success'=>false,'message'=>'Photo upload failed']);
}
$conn->close();
?>