×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Norman Liebich
Added: Feb 24, 2015 9:34 PM
Views: 2040
Tags: copy files
  1. function copyRemoteFile($remotePath, $localPath) {
  2.        
  3.         $rm_file = @fopen($remotePath, "rb");
  4.         if (!$rm_file) {
  5.             throw new Exception("Could not open " . $remotePath. ".");
  6.         }
  7.  
  8.         $lc_file = @fopen($localPath, "ab");
  9.  
  10.         if (!$lc_file) {
  11.             fclose($rm_file);
  12.             throw new Exception("Could not create local file " . $localPath . ".");
  13.         }
  14.  
  15.         while (!feof($rm_file)) {
  16.             $buffer = fread($rm_file, 8192);
  17.             fwrite($lc_file, $buffer);
  18.         }
  19.         fclose($rm_file);
  20.         fclose($lc_file);
  21.         return true;
  22.     }