how to Get file from another server and save it

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
haixiao
Forum Newbie
Posts: 2
Joined: Thu Dec 12, 2002 4:00 am

how to Get file from another server and save it

Post by haixiao »

how to Get file from another server and save it on running server ?
for example i want to save http://site.com/info.zip to my sever.
User avatar
Traduim
Forum Newbie
Posts: 11
Joined: Tue Dec 10, 2002 4:21 am
Location: Catalunya

Post by Traduim »

You may use FTP functions (http://www.php.net/ftp), or fopen() http://www.php.net/fopen.
haixiao
Forum Newbie
Posts: 2
Joined: Thu Dec 12, 2002 4:00 am

i get it

Post by haixiao »

<?

function copyFromRemote($remote,$local){
$fp1 = fopen($remote,"rb");
$fp2 = fopen($local,"wb");

while(!feof($fp1)) {
$line = fread($fp1,500000);
fputs($fp2,$line,strlen($line));
}
}
copyFromRemote("http://localhost/test/4.jpg","c:/temp/4.jpg");
?>
Post Reply