Copy Remote File Into Local Directory

October 19, 2006 | PHP

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

This post has one comment

  1. jhj 20/10/2009 at 19:28

    not work -_-


Leave a comment

Allowed tags are: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>