PHP

Copy Remote File Into Local Directory

Here is a little function used to copy file from remote directory (web server) into our local directory.

< ?php /* This function used to copy remote file into local disk Example: copyFile("http://test-server.com/file/movie.mpg","myfolder/"); */ function copyFile($url,$dirname){ @$file = fopen ($url, "rb"); if (!$file) { echo "Failed to copy $url !
";
return false;
}
else {
$filename = basename($url);
$fc = fopen($dirname."$filename", "wb");
while (!feof ($file)) {
$line = fread ($file, 1028);
fwrite($fc,$line);
}
fclose($fc);
echo "File $url saved to PC!
";
return true;
}
}
?>

This is very basic function. Be carefull, it will replace any existed file with the same name.

&nbsp;

1 Comment

  1. jhj

    not work -_-

Leave a Reply