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("","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);
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.


1 Comment

  1. jhj

    not work -_-

Leave a Reply