Created
September 26, 2019 14:33
-
-
Save webmasterninjay/fdbe3f8318f4922542263a1b314b9ee4 to your computer and use it in GitHub Desktop.
Simple PHP script to download file from url
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
<html> | |
<form method="post"> | |
<input name="url" size="50" /> | |
<input name="submit" type="submit" /> | |
</form> | |
<?php | |
// maximum execution time in seconds | |
set_time_limit (24 * 60 * 60); | |
if (!isset($_POST['submit'])) die(); | |
// folder to save downloaded files to. must end with slash | |
$destination_folder = 'downloads/'; | |
$url = $_POST['url']; | |
$newfname = $destination_folder . basename($url); | |
$file = fopen ($url, "rb"); | |
if ($file) { | |
$newf = fopen ($newfname, "wb"); | |
if ($newf) | |
while(!feof($file)) { | |
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); | |
} | |
} | |
if ($file) { | |
fclose($file); | |
} | |
if ($newf) { | |
fclose($newf); | |
} | |
?> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment