Code
Using PHP built-in function fopen we can read a remote stream, read the contents in the buffer and flush it to the file.

  1. // Copy remote file locally
  2. $remote_file = 'http://www.example.com/music.mp3';

  3. // open file
  4. if ($fp_remote = fopen($remote_file, 'rb')) {

  5.     // local filename
  6.     $local_file = '/tmp/music.mp3';

  7.      // read buffer
  8.     if ($fp_local = fopen($local_file, 'wb')) {
  9.         while ($buffer = fread($fp_remote, 8192)) {

  10.             // write buffer in file
  11.             fwrite($fp_local, $buffer);
  12.         }

  13.         // close local
  14.         fclose($fp_local);
  15.        
  16.     }
  17.     // close remote
  18.     fclose($fp_remote);
  19. }