Copy a remote file to local server

  $FileUrl = "http://mydomain.com/myimage.jpg";
  $ch = curl_init($FileUrl);
  $FileName = basename($ImageUrl);    // Get the file name and extension using basename()
  $SavePath = $_SERVER['DOCUMENT_ROOT'] . '/cameraimages/mysavedfilename.jpeg';
  $fp = fopen($SavePath, 'wb');
  
  curl_setopt($ch, CURLOPT_FILE, $fp);    // Set the file transfer option and header to CURL
  curl_setopt($ch, CURLOPT_HEADER, 0);

  curl_exec($ch);     // Execute the CURL session
  curl_close($ch);
  fclose($fp); 
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *