Hi,
is there a function in php which allows to download external file from another server, and put it in mine ?
Thank you
Hi,
is there a function in php which allows to download external file from another server, and put it in mine ?
Thank you
If it's activated on your web space, you can use
If you need to simulate a user-agent, do a log-in or other advanced stuff when downloading, you may want to look into the curl family of functions.
Hard core programmers who do it themselves use fsockopen() and consorts to build a connection from ground up.
you can use fopen/fread
function download($src, $dst) {
$f = fopen($src, 'rb');
$o = fopen($dst, 'wb');
while (!feof($f)) {
if (fwrite($o, fread($f, 2048)) === FALSE) {
return 1;
}
}
fclose($f);
fclose($o);
return 0;
}
download("http://www.somewhere/image.jpg","test.jpg");
There isn't a function that will read and write a remote file to a new location at the same time. That wouldn't be very useful in most cases. It's pretty easy to accomplish with a pair of functions though:
file_put_contents("local-file.jpg",file_get_contents("http://x.com/img.jpg"));