hello everyone ...
I am working on a CMS in PHP, using Apache server .. in my site we have a download and upload file module .. where user can download necessary files and also can upload .
but I want use an another server for this .... such that when user want to download a file through a link in my site , the file should be download from the 2nd server ... to reduce the overhead on the 1st server.

how to do this ... i don't have any idea regarding this ....

could you provide something ... some script or tutorial link .. by which i can able to understand the concept and i can proceed ...

thanks ....

You can copy a file to a remote server with PHP.

Say you have the two servers:


If you have a file on http://site.com/file.zip

You could just tell http://remote.com to download the file by giving it the url.



$file_url = 'http://site.com/file.zip';

$result = file_get_contents('http://remote.com/remote-download.php?file='.urlencode($file_url));

if ($result == 'ok') {
   echo 'file copied';
} else {
   echo 'failed';


Then on the page:


You could have something like:


$file_url = $_GET['file'];
$file = file_get_contents($file_url);

$result = file_put_contents('/path/to/files/'.base64_encode($file_url), $file);

echo $result ? 'ok' : 'fail';


Here "/path/to/files/" is the path to the directory you want to save the file.

Of course you need to put in some security measures and what not.

This article has been dead for over six months. Start a new discussion instead.