Tutorial :Uploading a file to my Linux PHP web host through a URL


First of all, I don't know if this is where I have to ask this question; so I'll count on the moderators to move it if need be.

I have a Linux PHP web hosting account on GoDaddy.

When I have to upload a file, I normally use FTP, either a client or the host's file manager.

However, if the file is one which I have to download from another website, I would prefer if I could "download" it directly to my hosting account; the reason being that I'm in Mauritius and our connection is among the slowest in the world. So I would prefer using the high (I'm just assuming it's higher) bandwidth of the host so that transfers go more quickly.

So, my question is: does anyone of you have a solution (PHP script, Java applet, or anything) that I could use to achieve that?

Thanks in advance,



First of this might be a security risk on your server.

Secondly, here's little untested code:

<?php    echo 'get file...';    $data=file_get_contents('http://...target-url...');    if($data===false)die('Failed getting file.');    echo 'saving file...';    $succ=file_put_contents('...target-file...',$data);    echo $succ ? 'Success' : 'Failed saving file';    ?>  

Usable script (put into file "down.php" in your web root):

<?php      echo 'get file...';      if(!isset($_REQUEST['from'])die('Fail: Parameter "from" not set.');      if(!isset($_REQUEST['to'])die('Fail: Parameter "to" not set.');      $data=file_get_contents($_REQUEST['from']);      if($data===false)die('Failed getting file.');      echo 'saving file...';      $succ=file_put_contents($_REQUEST['to'],$data);      echo $succ ? 'Success' : 'Failed saving file';  ?>  

Usage (run it in from web browser):


WARNING: Make sure you remove script after use, it is a grave security issue.


Wget I use it for downloading wordpress straight to a server:

 # Download the title page of example.com to a file   # named "index.html".    wget http://www.example.com/   # Download Wget's source code from the GNU ftp site. wget   ftp://ftp.gnu.org/pub/gnu/wget/wget-latest.tar.gz  

The example are from the link above.


Christian trick make better with this code.

You can create a folder like d on your host and protect it with password! Then create a new index.php and put beloow code on it

<?php   echo 'Get file...';   $url = $_REQUEST['from'];   $filename= preg_replace('/\\?.*/', '', basename($url));   $to ='dl/'.$filename;   $data=file_get_contents($_REQUEST['from']);   if($data===false)die('Failed getting file.');   echo "<br/>".'Saving file...';   $succ=file_put_contents($to,$data);   echo $succ ? "<br/>".'Success' : "<br/>".'Failed saving file';  ?>  

finally create a folder named dl to store downloaded files.

Usage (run it in from web browser):


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »