Skip to content

Instantly share code, notes, and snippets.

@ifeLight
Forked from karthikax/dosu.php
Created June 12, 2019 15:59
Show Gist options
  • Save ifeLight/8748b34c119d42031a3d5a6c09b62caa to your computer and use it in GitHub Desktop.
Save ifeLight/8748b34c119d42031a3d5a6c09b62caa to your computer and use it in GitHub Desktop.
PHP Download file to server from URL

PHP Download to Server from Url

Download files from any url to server directly.

  • Contributors: Karthik Bhat
  • Donate link: Official Donate Page
  • Script Platform: PHP
  • License: GPLv2 or later

Description

This script helps developers to download files from any url / other servers directly into their server without needing to download to local computer and then upload to the server.

Installation

  1. Download php-dosu.zip
  2. Extract the zip file.
  3. Inside php-dosu folder 'url-download.php' can be found. Upload it to root your server.
  4. Navigate to "YOURSITE.com/url-download.php"
  5. Enter the remote file url which you want to download directly to your server say "oldserver.com/bigfile.zip"
  6. Click download.

For more information about php-dosu please refer: PHP DoSU Official Page

<html>
<p style="width: 70%;margin: auto;margin-top: 5%;font-size:larger;text-align:center">
Download a file from any URL</p>
<form method="post" style="width: 70%;margin: auto;margin-top: 10%;">
<input name="url" size="50" placeholder="Source URL" style="width: 100%;height: 10%;font-size: 1.5em;padding:10px" required>
<input name="submit" type="submit" value="Download" style="width: 30%;height: 10%;margin: 5% auto; display: block;">
<p style="width: 70%;margin: auto;margin-top: 10%;font-size:larger;text-align:center">
To <?php echo getcwd(); ?></p>
<p style="width: 70%;margin: auto;font-size: smaller;text-align: center;position: fixed;bottom: 0;background: #fff;">
Powered by: <a href="https://karthikbhat.net/portfolio" target="_blank" style="color:#f60;text-decoration:none;">Karthik</a></p>
</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 = '';
$url = $_POST['url'];
$newfname = $destination_folder . basename($url);
/* // old script
$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); }
*/
file_put_contents( $newfname, fopen($url, 'r'));
?>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment