×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Dmitriy Lanets
Added: Mar 19, 2015 7:23 AM
Modified: Mar 19, 2015 9:01 AM
Views: 1887
Tags: helper
  1.                
  2.                 if (!$hfile = fopen($target, "w"))
  3.                         return false;
  4.  
  5.                 $ch = curl_init();
  6.                 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11');
  7.  
  8.                 curl_setopt($ch, CURLOPT_URL, $url);//ссылка на внешний ресурс файла
  9.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10.                 curl_setopt($ch, CURLOPT_FILE, $hfile);
  11.  
  12.                 if (!curl_exec($ch)) {
  13.                         curl_close($ch);
  14.                         fclose($hfile);
  15.                         unlink($target);
  16.                         return false;
  17.                 }
  18.  
  19.                 fflush($hfile);
  20.                 fclose($hfile);
  21.                 curl_close($ch);