Saturday, 8 April 2023

Copy file from external url using curl

 Copy file from external url using curl

if you want copy from https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvQdRe8XOy4RKAcBgzs2Cgggrj2PVg9A2hQTtcu34hQRi_7eQwwUixXYJXoFBoMPRp5B2x7ld98q4fnibANy9dtWZJyxg-Jj-btX-wzETe1SXBwhkXo6Kbr5lmzr8DFuUI20c-CeS7owUtDeLVL-__jBWK_Hrd4ct8aIByT51gSFffLW2LTUO41y3S/s1600/logo.gif

replace with https:// your  external url 


You want save this as sakhihosting.gif replace with  save as giving file name 

<?php

$ch = curl_init('https:// your  external url '); 

 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json'));

 $return = curl_exec($ch); 

  curl_close($ch); 

 print_r($return);

// $data = json_decode(file_get_contents($ch), true);

$file = fopen(" save as giving file name ","w");

echo fwrite($file,$return);

fclose($file);

?>