Skip to content

Instantly share code, notes, and snippets.

@EmmyWalt
Last active March 21, 2023 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EmmyWalt/ba5cccdec8c46573b2b85529c089c609 to your computer and use it in GitHub Desktop.
Save EmmyWalt/ba5cccdec8c46573b2b85529c089c609 to your computer and use it in GitHub Desktop.
This PHP code demonstrates how to download a remote file and save it locally using PHP's built-in functions. First, a simple HTML form is displayed with a single input field for the user to enter the URL of the file they wish to download. When the user submits the form, the PHP code is executed. Special thanks to https://chromewebextensions.com/
<?php
if(isset($_POST['download'])) {
$url = $_POST['url'];
$filename = basename($url);
$file = file_get_contents($url);
file_put_contents($filename, $file);
echo "File downloaded successfully!";
}
?>
<form method="POST" action="">
<label for="url">Enter file URL:</label>
<input type="text" name="url" id="url">
<input type="submit" name="download" value="Download">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment