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 ....

Look up mod_backhand for Apache

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:

http://site.com/
http://remote.com/

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.

eg:

<?php

$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:

http://remote.com/remote-download.php

You could have something like:

<?php

$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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.