Last active
March 21, 2023 19:49
-
-
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/ …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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