if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST["file_url"])) { $fileUrl = trim($_POST["file_url"]); echo downloadFile($fileUrl);}function downloadFile($fileUrl, $saveDir = "downloads/") { // Ensure the downloads directory exists if (!is_dir($saveDir)) { mkdir($saveDir, 0777, true); } // Get the file name from the URL $fileName = basename(parse_url($fileUrl, PHP_URL_PATH)); $savePath = $saveDir . $fileName; // Download the file $fileContent = file_get_contents($fileUrl); if ($fileContent === false) { return "<p style='color:red;'>Failed to download file.</p>"; } // Save the file if (file_put_contents($savePath, $fileContent)) { return "<p style='color:green;'>File downloaded successfully: <a href='$savePath' download>$fileName</a></p>"; } else { return "<p style='color:red;'>Failed to save file.</p>"; }}<!DOCTYPE html><html lang="en"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">File Downloader <title>File Downloader</title>

Download File to Server

<label>Enter File URL:</label>
<button type="submit">Download</button>