<?php
session_start();

header("Access-Control-Allow-Origin: https://enerliths.com");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST, OPTIONS");
header("Content-Type: application/json");

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}
include("../config/db.php");


$uploadDir = "uploads/";

if(!file_exists($uploadDir)){
    mkdir($uploadDir,0777,true);
}

$file = $_FILES['file'];

$name = time()."_".$file['name'];

move_uploaded_file($file['tmp_name'],$uploadDir.$name);

echo json_encode([
 "success"=>true,
 "file"=>$name
]);