English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have two websites that I sometimes need to copy files between and I don't want to have to download from the first then upload to the second each time. Is there a way to provide PHP with a URL to the external file and a location where you want the file to go and have it do a straight transfer?

2006-09-18 09:42:47 · 2 answers · asked by lots-a-questions 1 in Computers & Internet Programming & Design

2 answers

You could do something like this:

Website 1 has a file on it:
example.com/examplefile.whatever (as long as the extension is not php or the websites are on the same server, this should work.)

And Website 2 to wants to copy it:
$file = $_GET['source'];
$filecontents = file_get_contents($file);

$newfile = $_GET['file']

$handle = fopen($newfile, "x+");
fwrite($handle, $filecontents);
fclose($handle);

And voila! all you have to do is have a php script load:
example.php?create=example.txt&source=example.com/examplefile.whatever

2006-09-18 13:49:55 · answer #1 · answered by Alex V 3 · 0 0

I'm assuming that both websites are on different servers and not hosted by the same company (if they were, there would probably be an easier and faster way to do this - like scp):

See ch 39 of the PHP documentation: Remote Files

2006-09-18 17:16:38 · answer #2 · answered by George3 4 · 0 0

fedest.com, questions and answers