<?php
if (!isset($_POST['url']) || !isset($_POST['path'])) {
  http_response_code(400); // Bad Request
  echo json_encode(["error" => "URL and path are required."]);
  exit;
}
require_once('includes/load.php');

$url = $_POST['url'];
$path = $_POST['path'];

$isDownload = downloadFileFromUrl($url, $path);
if ($isDownload) {
  echo json_encode(["message" => "File downloaded successfully!", "path" => $path]);
} else {
  http_response_code(500); // Internal Server Error
  echo json_encode(["error" => "Failed to download file."]);
}
